{"id":977363,"date":"2024-12-27T06:28:57","date_gmt":"2024-12-26T22:28:57","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/977363.html"},"modified":"2024-12-27T06:28:59","modified_gmt":"2024-12-26T22:28:59","slug":"python%e5%88%97%e8%a1%a8%e5%a6%82%e4%bd%95%e5%8f%98%e6%88%90%e5%ad%97%e5%85%b8","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/977363.html","title":{"rendered":"python\u5217\u8868\u5982\u4f55\u53d8\u6210\u5b57\u5178"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24202638\/7eab0660-1ee5-42fd-9edf-2aa2b5559417.webp\" alt=\"python\u5217\u8868\u5982\u4f55\u53d8\u6210\u5b57\u5178\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u5b57\u5178\uff0c\u5982\u901a\u8fc7\u952e\u503c\u5bf9\u7ec4\u5408\u3001\u4f7f\u7528\u5b57\u5178\u63a8\u5bfc\u5f0f\u3001\u5229\u7528\u5185\u7f6e\u51fd\u6570zip()\u3001\u4ee5\u53ca\u901a\u8fc7enumerate()\u51fd\u6570\u7b49\u3002\u4f7f\u7528\u5b57\u5178\u63a8\u5bfc\u5f0f\u662f\u4e00\u79cd\u9ad8\u6548\u4e14\u7075\u6d3b\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u6c42\u81ea\u5b9a\u4e49\u952e\u548c\u503c\u7684\u751f\u6210\u65b9\u5f0f\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u5728Python\u7f16\u7a0b\u4e2d\uff0c\u5217\u8868\u548c\u5b57\u5178\u662f\u4e24\u79cd\u5e38\u7528\u7684\u6570\u636e\u7ed3\u6784\u3002\u5217\u8868\u662f\u4e00\u79cd\u6709\u5e8f\u7684\u96c6\u5408\uff0c\u9002\u7528\u4e8e\u5b58\u50a8\u4e00\u7ec4\u9879\u76ee\uff0c\u800c\u5b57\u5178\u662f\u4e00\u79cd\u65e0\u5e8f\u7684\u96c6\u5408\uff0c\u9002\u5408\u5b58\u50a8\u952e\u503c\u5bf9\u3002\u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u5b57\u5178\u7684\u9700\u6c42\u53ef\u80fd\u51fa\u73b0\u5728\u5404\u79cd\u573a\u666f\u4e2d\uff0c\u6bd4\u5982\u6570\u636e\u5904\u7406\u3001\u4fe1\u606f\u6620\u5c04\u7b49\u3002\u4ee5\u4e0b\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u51e0\u79cd\u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u5b57\u5178\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u901a\u8fc7\u952e\u503c\u5bf9\u7ec4\u5408<\/h3>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9002\u5408\u4e8e\u5217\u8868\u7684\u957f\u5ea6\u662f\u5076\u6570\u7684\u60c5\u51b5\uff0c\u56e0\u4e3a\u5217\u8868\u4e2d\u7684\u5143\u7d20\u9700\u8981\u6210\u5bf9\u51fa\u73b0\uff0c\u4e00\u4e2a\u4f5c\u4e3a\u952e\uff0c\u4e00\u4e2a\u4f5c\u4e3a\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">list_data = [&#39;a&#39;, 1, &#39;b&#39;, 2, &#39;c&#39;, 3]<\/p>\n<p>dict_data = {list_data[i]: list_data[i + 1] for i in range(0, len(list_data), 2)}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/h4>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u6cd5\uff0c\u4f60\u53ef\u4ee5\u5c06\u5217\u8868\u7684\u5143\u7d20\u6309\u987a\u5e8f\u6210\u5bf9\u7ec4\u5408\uff0c\u7b2c\u4e00\u4e2a\u5143\u7d20\u4f5c\u4e3a\u952e\uff0c\u7b2c\u4e8c\u4e2a\u5143\u7d20\u4f5c\u4e3a\u503c\u3002\u4f7f\u7528\u5b57\u5178\u63a8\u5bfc\u5f0f\u53ef\u4ee5\u7b80\u5316\u4ee3\u7801\u5e76\u63d0\u9ad8\u53ef\u8bfb\u6027\u3002\u5728\u8fd9\u79cd\u65b9\u6cd5\u4e2d\uff0c\u9700\u8981\u786e\u4fdd\u5217\u8868\u7684\u957f\u5ea6\u662f\u5076\u6570\uff0c\u5426\u5219\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u5c06\u6ca1\u6709\u5bf9\u5e94\u7684\u952e\u6216\u503c\uff0c\u8fd9\u53ef\u80fd\u5bfc\u81f4\u9519\u8bef\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528\u5b57\u5178\u63a8\u5bfc\u5f0f<\/h3>\n<\/p>\n<p><p>\u5b57\u5178\u63a8\u5bfc\u5f0f\u662f\u4e00\u79cd\u9ad8\u6548\u3001\u7b80\u6d01\u7684\u5b57\u5178\u521b\u5efa\u65b9\u5f0f\uff0c\u5141\u8bb8\u7528\u6237\u6839\u636e\u9700\u6c42\u81ea\u5b9a\u4e49\u952e\u548c\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">list_data = [&#39;name&#39;, &#39;Alice&#39;, &#39;age&#39;, 30, &#39;city&#39;, &#39;New York&#39;]<\/p>\n<p>dict_data = {list_data[i]: list_data[i + 1] for i in range(0, len(list_data), 2)}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/h4>\n<\/p>\n<p><p>\u5b57\u5178\u63a8\u5bfc\u5f0f\u548c\u5217\u8868\u63a8\u5bfc\u5f0f\u7c7b\u4f3c\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u79cd\u76f4\u89c2\u7684\u65b9\u5f0f\u6765\u521b\u5efa\u5b57\u5178\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u6cd5\uff0c\u7528\u6237\u53ef\u4ee5\u7075\u6d3b\u5730\u5b9a\u4e49\u952e\u548c\u503c\u7684\u751f\u6210\u89c4\u5219\u3002\u5bf9\u4e8e\u4e0d\u7b26\u5408\u952e\u503c\u5bf9\u8981\u6c42\u7684\u5217\u8868\u6570\u636e\uff0c\u53ef\u4ee5\u5148\u901a\u8fc7\u6761\u4ef6\u5224\u65ad\u6216\u6570\u636e\u9884\u5904\u7406\u7684\u65b9\u5f0f\u8fdb\u884c\u8c03\u6574\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u5229\u7528\u5185\u7f6e\u51fd\u6570zip()<\/h3>\n<\/p>\n<p><p>zip()\u51fd\u6570\u53ef\u4ee5\u5c06\u591a\u4e2a\u53ef\u8fed\u4ee3\u5bf9\u8c61\u4e2d\u7684\u5143\u7d20\u6253\u5305\u6210\u4e00\u4e2a\u4e2a\u5143\u7ec4\uff0c\u5e76\u8fd4\u56de\u8fd9\u4e9b\u5143\u7ec4\u7ec4\u6210\u7684\u8fed\u4ee3\u5668\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">keys = [&#39;name&#39;, &#39;age&#39;, &#39;city&#39;]<\/p>\n<p>values = [&#39;Alice&#39;, 30, &#39;New York&#39;]<\/p>\n<p>dict_data = dict(zip(keys, values))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/h4>\n<\/p>\n<p><p>zip()\u51fd\u6570\u7684\u5e94\u7528\u975e\u5e38\u5e7f\u6cdb\uff0c\u5b83\u53ef\u4ee5\u5c06\u4e24\u4e2a\u5217\u8868\u7684\u5143\u7d20\u4e00\u4e00\u5bf9\u5e94\u5730\u5408\u5e76\u4e3a\u952e\u503c\u5bf9\uff0c\u5f62\u6210\u5b57\u5178\u3002\u8fd9\u79cd\u65b9\u6cd5\u7b80\u5355\u6613\u61c2\uff0c\u4f46\u8981\u6c42\u4e24\u4e2a\u5217\u8868\u7684\u957f\u5ea6\u76f8\u540c\u3002\u5982\u679c\u957f\u5ea6\u4e0d\u540c\uff0czip()\u51fd\u6570\u4f1a\u6309\u7167\u6700\u77ed\u7684\u5217\u8868\u8fdb\u884c\u622a\u65ad\uff0c\u53ef\u80fd\u4f1a\u4e22\u5931\u90e8\u5206\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u901a\u8fc7enumerate()\u51fd\u6570<\/h3>\n<\/p>\n<p><p>enumerate()\u51fd\u6570\u7528\u4e8e\u5c06\u4e00\u4e2a\u53ef\u8fed\u4ee3\u5bf9\u8c61\u7ec4\u5408\u4e3a\u4e00\u4e2a\u7d22\u5f15\u5e8f\u5217\uff0c\u4f7f\u6211\u4eec\u53ef\u4ee5\u540c\u65f6\u83b7\u5f97\u7d22\u5f15\u548c\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">list_data = [&#39;Alice&#39;, &#39;Bob&#39;, &#39;Charlie&#39;]<\/p>\n<p>dict_data = {i: name for i, name in enumerate(list_data)}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/h4>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5c06\u5217\u8868\u7684\u7d22\u5f15\u4f5c\u4e3a\u5b57\u5178\u7684\u952e\uff0c\u5217\u8868\u7684\u5143\u7d20\u4f5c\u4e3a\u5b57\u5178\u7684\u503c\u3002\u8fd9\u79cd\u65b9\u5f0f\u9002\u5408\u4e8e\u9700\u8981\u4fdd\u7559\u5143\u7d20\u987a\u5e8f\u4e14\u4e0d\u5173\u5fc3\u5177\u4f53\u952e\u540d\u7684\u60c5\u51b5\u3002\u5bf9\u4e8e\u9700\u8981\u81ea\u5b9a\u4e49\u952e\u540d\u7684\u573a\u666f\uff0c\u53ef\u4ee5\u7ed3\u5408\u5176\u4ed6\u65b9\u6cd5\u8fdb\u884c\u8c03\u6574\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u901a\u8fc7\u5faa\u73af\u624b\u52a8\u6784\u5efa<\/h3>\n<\/p>\n<p><p>\u624b\u52a8\u6784\u5efa\u5b57\u5178\u662f\u4e00\u79cd\u7075\u6d3b\u4f46\u7a0d\u663e\u7e41\u7410\u7684\u65b9\u6cd5\uff0c\u9002\u7528\u4e8e\u9700\u8981\u590d\u6742\u903b\u8f91\u6216\u5904\u7406\u7684\u573a\u5408\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">list_data = [&#39;name&#39;, &#39;Alice&#39;, &#39;age&#39;, 30, &#39;city&#39;, &#39;New York&#39;]<\/p>\n<p>dict_data = {}<\/p>\n<p>for i in range(0, len(list_data), 2):<\/p>\n<p>    dict_data[list_data[i]] = list_data[i + 1]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/h4>\n<\/p>\n<p><p>\u624b\u52a8\u6784\u5efa\u5b57\u5178\u9002\u5408\u4e8e\u9700\u8981\u5728\u8f6c\u6362\u8fc7\u7a0b\u4e2d\u8fdb\u884c\u989d\u5916\u5904\u7406\u6216\u9a8c\u8bc1\u7684\u573a\u666f\u3002\u867d\u7136\u4ee3\u7801\u91cf\u8f83\u5927\uff0c\u4f46\u8fd9\u79cd\u65b9\u6cd5\u63d0\u4f9b\u4e86\u6700\u5927\u7684\u7075\u6d3b\u6027\uff0c\u53ef\u4ee5\u5728\u6784\u5efa\u8fc7\u7a0b\u4e2d\u63d2\u5165\u4efb\u4f55\u6240\u9700\u7684\u903b\u8f91\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u4f7f\u7528collections\u6a21\u5757\u7684defaultdict<\/h3>\n<\/p>\n<p><p>collections\u6a21\u5757\u63d0\u4f9b\u4e86\u4e00\u4e9b\u6709\u7528\u7684\u96c6\u5408\u7c7b\uff0cdefaultdict\u662f\u5176\u4e2d\u4e4b\u4e00\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5904\u7406\u7f3a\u5931\u952e\u7684\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from collections import defaultdict<\/p>\n<p>list_data = [&#39;name&#39;, &#39;Alice&#39;, &#39;age&#39;, 30, &#39;city&#39;, &#39;New York&#39;]<\/p>\n<p>dict_data = defaultdict(list)<\/p>\n<p>for i in range(0, len(list_data), 2):<\/p>\n<p>    dict_data[list_data[i]].append(list_data[i + 1])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/h4>\n<\/p>\n<p><p>defaultdict\u662f\u5b57\u5178\u7684\u4e00\u4e2a\u5b50\u7c7b\uff0c\u5b83\u91cd\u5199\u4e86__missing__\u65b9\u6cd5\uff0c\u4f7f\u5f97\u8bbf\u95ee\u4e0d\u5b58\u5728\u7684\u952e\u65f6\u4e0d\u4f1a\u5f15\u53d1KeyError\uff0c\u800c\u662f\u8fd4\u56de\u4e00\u4e2a\u9ed8\u8ba4\u503c\u3002\u4f7f\u7528defaultdict\u53ef\u4ee5\u907f\u514d\u5728\u5904\u7406\u952e\u503c\u5bf9\u65f6\u56e0\u91cd\u590d\u952e\u5bfc\u81f4\u7684\u6570\u636e\u4e22\u5931\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u4f7f\u7528pandas\u5e93<\/h3>\n<\/p>\n<p><p>\u5bf9\u4e8e\u9700\u8981\u5904\u7406\u590d\u6742\u6570\u636e\u7ed3\u6784\u6216\u8fdb\u884c\u6570\u636e\u5206\u6790\u7684\u573a\u666f\uff0cpandas\u5e93\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u636e\u64cd\u4f5c\u80fd\u529b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>list_data = [&#39;name&#39;, &#39;Alice&#39;, &#39;age&#39;, 30, &#39;city&#39;, &#39;New York&#39;]<\/p>\n<p>dict_data = pd.Series(list_data[1::2], index=list_data[0::2]).to_dict()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/h4>\n<\/p>\n<p><p>pandas\u5e93\u662fPython\u4e2d\u6570\u636e\u5206\u6790\u7684\u5229\u5668\uff0c\u4f7f\u7528\u5b83\u53ef\u4ee5\u65b9\u4fbf\u5730\u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u5b57\u5178\uff0c\u5c24\u5176\u662f\u5728\u6570\u636e\u683c\u5f0f\u590d\u6742\u6216\u8005\u9700\u8981\u8fdb\u4e00\u6b65\u5904\u7406\u7684\u60c5\u51b5\u4e0b\u3002\u901a\u8fc7pandas\u7684Series\u5bf9\u8c61\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u521b\u5efa\u952e\u503c\u5bf9\u5e76\u8fdb\u884c\u540e\u7eed\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h3>\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u5b57\u5178\u662fPython\u7f16\u7a0b\u4e2d\u4e00\u79cd\u5e38\u89c1\u7684\u64cd\u4f5c\uff0c\u5177\u4f53\u91c7\u7528\u54ea\u79cd\u65b9\u6cd5\u53d6\u51b3\u4e8e\u5b9e\u9645\u9700\u6c42\u548c\u6570\u636e\u7279\u6027\u3002\u901a\u8fc7\u4e86\u89e3\u4e0d\u540c\u65b9\u6cd5\u7684\u4f18\u7f3a\u70b9\uff0c\u53ef\u4ee5\u9009\u62e9\u6700\u9002\u5408\u5f53\u524d\u573a\u666f\u7684\u65b9\u6848\uff0c\u4ee5\u5b9e\u73b0\u9ad8\u6548\u7684\u6570\u636e\u8f6c\u6362\u548c\u5904\u7406\u3002\u65e0\u8bba\u662f\u901a\u8fc7\u57fa\u672c\u7684\u5185\u7f6e\u51fd\u6570\u8fd8\u662f\u5229\u7528\u5916\u90e8\u5e93\uff0cPython\u90fd\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u5de5\u5177\u6765\u6ee1\u8db3\u5f00\u53d1\u8005\u7684\u5404\u79cd\u9700\u6c42\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5c06Python\u5217\u8868\u8f6c\u6362\u4e3a\u5b57\u5178\uff1f<\/strong><\/p>\n<p>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u5b57\u5178\u3002\u6700\u5e38\u89c1\u7684\u65b9\u6cd5\u662f\u4f7f\u7528\u5b57\u5178\u63a8\u5bfc\u5f0f\u6216\u5185\u7f6e\u7684<code>dict()<\/code>\u51fd\u6570\u3002\u5982\u679c\u4f60\u7684\u5217\u8868\u5305\u542b\u952e\u503c\u5bf9\uff0c\u53ef\u4ee5\u76f4\u63a5\u5c06\u5176\u8f6c\u6362\u4e3a\u5b57\u5178\u3002\u4f8b\u5982\uff0c\u5047\u8bbe\u4f60\u6709\u4e00\u4e2a\u5305\u542b\u5143\u7ec4\u7684\u5217\u8868\uff0c\u6bcf\u4e2a\u5143\u7ec4\u5305\u542b\u4e00\u4e2a\u952e\u548c\u4e00\u4e2a\u5bf9\u5e94\u7684\u503c\uff0c\u4f60\u53ef\u4ee5\u8fd9\u6837\u505a\uff1a<\/p>\n<pre><code class=\"language-python\">list_of_tuples = [(&#39;a&#39;, 1), (&#39;b&#39;, 2), (&#39;c&#39;, 3)]\ndictionary = dict(list_of_tuples)\n<\/code><\/pre>\n<p><strong>\u5982\u679c\u5217\u8868\u4e2d\u6709\u91cd\u590d\u7684\u952e\uff0c\u8be5\u5982\u4f55\u5904\u7406\uff1f<\/strong><\/p>\n<p>\u5728Python\u4e2d\uff0c\u5b57\u5178\u7684\u952e\u662f\u552f\u4e00\u7684\uff0c\u5982\u679c\u5728\u8f6c\u6362\u8fc7\u7a0b\u4e2d\u9047\u5230\u91cd\u590d\u7684\u952e\uff0c\u53ea\u6709\u6700\u540e\u4e00\u4e2a\u503c\u4f1a\u88ab\u4fdd\u7559\u3002\u53ef\u4ee5\u901a\u8fc7\u5728\u8f6c\u6362\u4e4b\u524d\u53bb\u91cd\u6216\u4f7f\u7528<code>collections.defaultdict<\/code>\u6765\u5904\u7406\u91cd\u590d\u952e\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>defaultdict<\/code>\u53ef\u4ee5\u5c06\u76f8\u540c\u7684\u952e\u7684\u503c\u5b58\u50a8\u4e3a\u5217\u8868\uff1a<\/p>\n<pre><code class=\"language-python\">from collections import defaultdict\n\nlist_of_p<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>rs = [(&#39;a&#39;, 1), (&#39;b&#39;, 2), (&#39;a&#39;, 3)]\nresult = defaultdict(list)\n\nfor key, value in list_of_pairs:\n    result[key].append(value)\n\ndictionary = dict(result)\n<\/code><\/pre>\n<p><strong>\u5982\u4f55\u5c06\u4e24\u4e2a\u5217\u8868\u5206\u522b\u4f5c\u4e3a\u952e\u548c\u503c\u6765\u521b\u5efa\u5b57\u5178\uff1f<\/strong><\/p>\n<p>\u5982\u679c\u4f60\u6709\u4e24\u4e2a\u5217\u8868\uff0c\u4e00\u4e2a\u5305\u542b\u952e\uff0c\u53e6\u4e00\u4e2a\u5305\u542b\u76f8\u5e94\u7684\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528<code>zip()<\/code>\u51fd\u6570\u5c06\u5b83\u4eec\u7ed3\u5408\u8d77\u6765\u5e76\u521b\u5efa\u5b57\u5178\u3002\u4f8b\u5982\uff0c\u5047\u8bbe\u6709\u4e00\u4e2a\u952e\u5217\u8868\u548c\u4e00\u4e2a\u503c\u5217\u8868\uff0c\u4f60\u53ef\u4ee5\u8fd9\u6837\u505a\uff1a<\/p>\n<pre><code class=\"language-python\">keys = [&#39;name&#39;, &#39;age&#39;, &#39;city&#39;]\nvalues = [&#39;Alice&#39;, 30, &#39;New York&#39;]\ndictionary = dict(zip(keys, values))\n<\/code><\/pre>\n<p>\u8fd9\u6837\uff0c\u4f60\u5c31\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06\u4e24\u4e2a\u5217\u8868\u7ec4\u5408\u6210\u4e00\u4e2a\u5b57\u5178\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u6cd5\u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u5b57\u5178\uff0c\u5982\u901a\u8fc7\u952e\u503c\u5bf9\u7ec4\u5408\u3001\u4f7f\u7528\u5b57\u5178\u63a8\u5bfc\u5f0f\u3001\u5229\u7528\u5185\u7f6e\u51fd\u6570zip()\u3001 [&hellip;]","protected":false},"author":3,"featured_media":977377,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/977363"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=977363"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/977363\/revisions"}],"predecessor-version":[{"id":977378,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/977363\/revisions\/977378"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/977377"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=977363"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=977363"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=977363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}