{"id":164911,"date":"2020-09-30T02:45:58","date_gmt":"2020-09-29T18:45:58","guid":{"rendered":"http:\/\/4563.org\/?p=164911"},"modified":"2020-09-30T02:45:58","modified_gmt":"2020-09-29T18:45:58","slug":"%e5%86%99%e9%94%99-python-%e9%83%a8%e5%88%86%e4%bb%a3%e7%a0%81%ef%bc%8c%e7%bb%93%e6%9e%9c%e8%ae%a9%e6%88%91%e6%83%b3%e4%b8%8d%e6%98%8e%e7%99%bd","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=164911","title":{"rendered":"\u5199\u9519 Python \u90e8\u5206\u4ee3\u7801\uff0c\u7ed3\u679c\u8ba9\u6211\u60f3\u4e0d\u660e\u767d"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u5199\u9519 Python \u90e8\u5206\u4ee3\u7801\uff0c\u7ed3\u679c\u8ba9\u6211\u60f3\u4e0d\u660e\u767d               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : crella <\/span>  <span><i><\/i> 6<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u95ee\u9898\u6bd4\u8f83\u96be\u63cf\u8ff0\u3002\u6211\u662f\u65b0\u624b\uff0c\u672c\u6765\u6211\u662f\u7528 Ruby \u5199\u5168\u6392\u5217\u7b97\u6cd5\u751f\u6210\u5668\u7684\uff0c\u7136\u540e\u60f3\u770b Python \u600e\u4e48\u5199\u3002\u6211\u4e0d\u61c2 Python\uff0c\u6240\u4ee5\u770b\u522b\u4eba\u600e\u4e48\u7528 yield \u4e5f\u5c31\u968f\u4fbf\u7528\u3002\u95ee\u9898\u51fa\u5728\u6211\u5199\u9519\u7684\u6700\u540e\u4e00\u53e5\uff1aprint(&#8216;,&#8217;.join(str(o)))\uff0c\u6253\u5370\u7684\u7ed3\u679c\u6211\u5b9e\u5728\u770b\u4e0d\u61c2\uff0c\u6216\u8bb8\u662f\u6211\u4e0d\u61c2 yield \u7684\u6d41\u7a0b\u3002\u662f\u6211\u7684 yield \u54ea\u91cc\u5199\u9519\u4e86\u5417\uff1f<\/p>\n<pre><code># \u751f\u6210\u6570\u7ec4[1,2,3,4]\u7684\u5168\u90e8\u5143\u7d20\u7684\u5168\u6392\u5217 def scan(src, m, n):   if (m == n):     yield src   else:     for i in range(m, (n+1)):       # \u4ea4\u6362       tmp = src[m]       src[m] = src[i]       src[i] = tmp              # \u9012\u5f52       for _ in scan(src, (m+1), n):         yield _              # \u6062\u590d\u4ea4\u6362\u524d       tmp = src[m]       src[m] = src[i]       src[i] = tmp         def perm_core(src):   n = len(src) - 1   for _ in scan(src, 0, n):     yield _   # main list = [i for i in range(1, 5)] for o in perm_core(list):   # ~ w = [str(y) for y in o]   # ~ print (','.join(w)) # \u6b63\u786e\u4ee3\u7801      print(','.join(str(o))) # \u9519\u8bef\u4ee3\u7801  <\/code><\/pre>\n<p>\u6253\u5370\u7ed3\u679c<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/10\/20201009_5f80d9adb4c79.jpg\" alt=\"\u5199\u9519 Python \u90e8\u5206\u4ee3\u7801\uff0c\u7ed3\u679c\u8ba9\u6211\u60f3\u4e0d\u660e\u767d\" \/><\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>6<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3620042\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : binux <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u4e0d\u61c2 join                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3620043\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Pagliacii <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             https:\/\/sm.ms\/image\/G54yMndwJrOcEgN<\/p>\n<p>\u95ee\u9898\u5728\u4e8e\u4f60\u76f4\u63a5\u5c06\u5217\u8868\u4f5c\u4e3a\u53c2\u6570\u4f20\u7ed9\u4e86 str\uff0c\u7ed3\u679c\u5c31\u5982\u56fe\u6240\u793a\u4e86                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3620044\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : superrichman <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u7684\u95ee\u9898\u4e0a\u8bf4\u4e86\uff0c\u4f20\u7ed9 str \u7684\u53c2\u6570\u6709\u95ee\u9898\uff0c\u4f60\u9700\u8981\u5bf9\u5217\u8868\u91cc\u6bcf\u4e00\u4e2a\u5143\u7d20\u8f6c str \u800c\u4e0d\u662f\u6574\u4e2a\u5217\u8868\u8f6c str \u3002<\/p>\n<p>\u5176\u5b9e\u9700\u8981\u5b57\u7b26\u4e32\u7684\u5217\u8868\u5728\u5217\u8868\u751f\u6210\u7684\u65f6\u5019\u5c31\u53ef\u4ee5\u8f6c\u4e86\uff0c\u6bd4\u5982\u628a i \u6539\u6210 str(i)<br \/>list = [str(i) for i in range(1, 5)]<br \/>\u4e0d\u8fc7\u53d8\u91cf\u4e0d\u8981\u53d6\u540d\u4e3a list\uff0c\u8fd9\u4f1a\u548c python \u5185\u7f6e\u7684 list \u51fd\u6570\u51b2\u7a81\uff0c\u53ef\u80fd\u4f1a\u5f15\u8d77\u5176\u5b83\u95ee\u9898\u3002<\/p>\n<p>python \u5185\u7f6e\u6a21\u5757\u6709\u6392\u5217\u7ec4\u5408\u7684\u529f\u80fd\uff0c \u53ef\u4ee5\u53bb\u641c\u7d22\u5173\u952e\u5b57 itertools permutation combination\uff0c\u5185\u7f6e\u7684\u5b9e\u73b0\u4e00\u822c\u8fd0\u884c\u6548\u7387\u4f1a\u6bd4\u81ea\u5df1\u5199\u7684\u9ad8<\/p>\n<p>python \u4ea4\u6362\u53d8\u91cf\u7684\u503c\uff0c\u53ef\u4ee5\u4e0d\u7528\u81ea\u5df1\u58f0\u660e\u4e34\u65f6\u53d8\u91cf\uff0c\u76f4\u63a5<br \/>a, b = b, a<br \/>\u5b8c\u6210\u4ea4\u6362                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3620045\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Pagliacii <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5b9e\u9645\u4e0a\u4f60\u7528\u9012\u5f52\u6765\u5199\u7684\u8bdd\uff0c\u53ef\u4ee5\u5199\u5f97\u66f4\u7b80\u77ed\u4e00\u70b9\uff0c\u5c31\u50cf\u8fd9\u6837\uff1a<\/p>\n<p>https:\/\/i.loli.net\/2020\/10\/02\/idFkXWS6LjNgr1v.png                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3620046\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Pagliacii <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Pagliacii #4 \u6211\u5199\u7684\u8fd9\u6bb5\u4ee3\u7801\u6ca1\u8003\u8651\u7a7a\u5217\u8868\u7684\u60c5\u51b5\uff0c\u53ef\u4ee5\u5c06 `len(l) == 1` \u6539\u6210 `len(l) &lt; 2`\u3002<\/p>\n<p>\u53e6\u5916\u6700\u91cc\u5c42\u5faa\u73af\u4f53\u53ef\u4ee5\u7b80\u5355\u5730\u7528 `yield [i] + others` \u6765\u4ee3\u66ff                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3620047\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : crella <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u60f3\u660e\u767d\u4e86\uff0cPython \u91cc str1.join(str2) \u8868\u793a str2 \u7684\u6bcf\u4e2a\u5b57\u7b26\u7528 str1 \u76f8\u8fde                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u5199\u9519 Python \u90e8\u5206\u4ee3\u7801\uff0c\u7ed3\u679c&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/164911"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=164911"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/164911\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=164911"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=164911"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=164911"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}