{"id":301,"date":"2021-08-13T06:41:00","date_gmt":"2021-08-13T06:41:00","guid":{"rendered":"https:\/\/262235.xyz\/?p=301"},"modified":"2021-08-13T06:41:00","modified_gmt":"2021-08-13T06:41:00","slug":"301","status":"publish","type":"post","link":"https:\/\/lyvba.com\/index.php\/2021\/08\/13\/301\/","title":{"rendered":"Python\u548cPHP\u5b66\u4e60: \u6570\u5b57\u6570\u7ec4 \u548c \u5b57\u7b26\u7a9c\u6570\u7ec4 \u76f8\u4e58"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/08\/1263495248.png\" alt=\"list.png\" title=\"list.png\"><\/p>\n<h2>\u7b14\u8bb0\u5185\u5bb9: \u6570\u7ec4\u5b9a\u4e49\u64cd\u4f5c, if for \u590d\u5408\u8bed\u53e5\u4f7f\u7528\uff0c len range enumerate split \u51fd\u6570<\/h2>\n<h3>python \u7248\u672c<\/h3>\n<pre><code># \u6570\u5b57\u6570\u7ec4 \u548c \u5b57\u7b26\u7a9c\u6570\u7ec4 \u76f8\u4e58\nlist1 = [1, 2, 3, 1]\nlist2 = ['A', 'B', 'C', 'End']\n\n# \u5b9a\u4e49\u51fd\u6570 \u8f93\u5165\u4e00\u4e2a\u5b57\u7b26(\u7a9c) \u548c \u6570\u5b57\uff0c \u8fd4\u56de ',' \u76f8\u9694\u7684\u5b57\u7b26\u7a9c\ndef foo(ch, n):\n    s = ''\n    for i in range(n):\n        s = s + ch + ','\n    return s\n\n# \u5224\u65ad \u6570\u5b57\u6570\u7ec4 \u548c \u5b57\u7b26\u7a9c\u6570\u7ec4 \u5143\u7d20\u4e2a\u6570\u60f3\u5426\u76f8\u540c\nimport sys\nif len(list1) != len(list2):\n    sys.exit(1)\n\ns = ''   # \u679a\u4e3e\u5b57\u7b26\u4e32\u6570\u7ec4\uff0c\u8c03\u7528\u51fd\u6570\u548c\u6570\u5b57\u6570\u7ec4\u76f8\u4e58\nfor i, ch in enumerate(list2):\n    s += foo(ch, list1[i])\n\n# \u5220\u9664\u6700\u540e\u4e00\u4e2a',' \u4f7f\u7528split\u51fd\u6570\u628a\u5b57\u7b26\u4e32\u8f6c\u6210\u6570\u7ec4\ns = s[0:-1]\nlist3 = s.split(',')\nprint(list3)<\/code><\/pre>\n<h2>PHP\u7248\u672c<\/h2>\n<pre><code>&lt;?php\n# \u6570\u5b57\u6570\u7ec4 \u548c \u5b57\u7b26\u7a9c\u6570\u7ec4 \u76f8\u4e58\n$list1 = [1, 2, 3, 1];\n$list2 = ['A', 'B', 'C', 'End'];\n\n# \u5b9a\u4e49\u51fd\u6570 \u8f93\u5165\u4e00\u4e2a\u5b57\u7b26(\u7a9c) \u548c \u6570\u5b57\uff0c \u8fd4\u56de ',' \u76f8\u9694\u7684\u5b57\u7b26\u7a9c\nfunction foo($ch, $n){\n    $s = '';\n    for($i = 0; $i != $n; $i++)\n        $s .= ($ch. ',');\n    return $s;\n}\n\n# \u5224\u65ad \u6570\u5b57\u6570\u7ec4 \u548c \u5b57\u7b26\u7a9c\u6570\u7ec4 \u5143\u7d20\u4e2a\u6570\u60f3\u5426\u76f8\u540c\nif (sizeof($list1) != sizeof($list2))\n    exit;\n\n$s = '';   # \u679a\u4e3e\u5b57\u7b26\u4e32\u6570\u7ec4\uff0c\u8c03\u7528\u51fd\u6570\u548c\u6570\u5b57\u6570\u7ec4\u76f8\u4e58\nfor ($i = 0; $i != sizeof($list2); $i++)\n    $s .= foo($list2[$i], $list1[$i]);\n\n# \u5220\u9664\u6700\u540e\u4e00\u4e2a',' \u4f7f\u7528split\u51fd\u6570\u628a\u5b57\u7b26\u4e32\u8f6c\u6210\u6570\u7ec4\n$s = rtrim($s, ',');    # rtrim \u2014 \u5220\u9664\u5b57\u7b26\u4e32\u672b\u7aef\u7684\u7a7a\u767d\u5b57\u7b26\uff08\u6216\u8005\u5176\u4ed6\u5b57\u7b26\uff09\n$list3 = explode(',', $s);  # explode \u2014 \u4f7f\u7528\u4e00\u4e2a\u5b57\u7b26\u4e32\u5206\u5272\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32\nprint_r($list3);        # var_dump($list3);\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7b14\u8bb0\u5185\u5bb9: \u6570\u7ec4\u5b9a\u4e49\u64cd\u4f5c, if for \u590d\u5408\u8bed\u53e5\u4f7f\u7528\uff0c len range enumerate s [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[34,45],"class_list":["post-301","post","type-post","status-publish","format-standard","hentry","category-learn","tag-php","tag-python"],"_links":{"self":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/301","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/comments?post=301"}],"version-history":[{"count":0,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/301\/revisions"}],"wp:attachment":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/media?parent=301"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/categories?post=301"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/tags?post=301"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}