{"id":1075862,"date":"2025-01-08T11:48:06","date_gmt":"2025-01-08T03:48:06","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1075862.html"},"modified":"2025-01-08T11:48:10","modified_gmt":"2025-01-08T03:48:10","slug":"python%e5%ad%97%e5%85%b8%e4%b8%ad%e5%a6%82%e4%bd%95%e7%9f%a5%e9%81%93%e5%80%bc%e6%89%be%e9%94%ae-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1075862.html","title":{"rendered":"Python\u5b57\u5178\u4e2d\u5982\u4f55\u77e5\u9053\u503c\u627e\u952e"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24180717\/fb89e59d-de21-4d10-8528-0ce3ed63a03c.webp\" alt=\"Python\u5b57\u5178\u4e2d\u5982\u4f55\u77e5\u9053\u503c\u627e\u952e\" \/><\/p>\n<p><p> \u5728Python\u5b57\u5178\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u503c\u6765\u67e5\u627e\u5bf9\u5e94\u7684\u952e\u3002<strong>\u901a\u8fc7\u8fed\u4ee3\u5b57\u5178\u9879\u3001\u4f7f\u7528\u5b57\u5178\u63a8\u5bfc\u5f0f\u3001\u53cd\u8f6c\u5b57\u5178<\/strong>\u7b49\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u8fd9\u4e00\u70b9\u3002\u4ee5\u4e0b\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u5e76\u63d0\u4f9b\u5b9e\u9645\u7684\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u76f4\u63a5\u56de\u7b54\u6807\u9898\u6240\u63d0\u95ee\u9898\uff1a\u5728Python\u5b57\u5178\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u503c\u6765\u67e5\u627e\u5bf9\u5e94\u7684\u952e\uff0c\u4e3b\u8981\u65b9\u6cd5\u5305\u62ec<strong>\u8fed\u4ee3\u5b57\u5178\u9879<\/strong>\u3001<strong>\u5b57\u5178\u63a8\u5bfc\u5f0f<\/strong>\u4ee5\u53ca<strong>\u53cd\u8f6c\u5b57\u5178<\/strong>\u3002\u5176\u4e2d\uff0c<strong>\u8fed\u4ee3\u5b57\u5178\u9879<\/strong>\u662f\u6700\u5e38\u7528\u4e14\u76f4\u89c2\u7684\u65b9\u6cd5\uff0c\u5b83\u901a\u8fc7\u904d\u5386\u6574\u4e2a\u5b57\u5178\u6765\u627e\u5230\u5bf9\u5e94\u7684\u952e\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u8fed\u4ee3\u5b57\u5178\u9879<\/h3>\n<\/p>\n<p><p>\u8fed\u4ee3\u5b57\u5178\u9879\u662f\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u4e4b\u4e00\u3002\u901a\u8fc7\u904d\u5386\u5b57\u5178\u7684\u952e\u503c\u5bf9\uff0c\u53ef\u4ee5\u627e\u5230\u4e0e\u6307\u5b9a\u503c\u5339\u914d\u7684\u952e\u3002\u8fd9\u79cd\u65b9\u6cd5\u7b80\u5355\u6613\u61c2\uff0c\u4f46\u5728\u5927\u5b57\u5178\u4e2d\u53ef\u80fd\u6548\u7387\u8f83\u4f4e\u3002<\/p>\n<\/p>\n<p><h4>1. \u57fa\u672c\u793a\u4f8b<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">def find_key_by_value(d, value):<\/p>\n<p>    for k, v in d.items():<\/p>\n<p>        if v == value:<\/p>\n<p>            return k<\/p>\n<p>    return None<\/p>\n<h2><strong>\u793a\u4f8b\u5b57\u5178<\/strong><\/h2>\n<p>my_dict = {&#39;a&#39;: 1, &#39;b&#39;: 2, &#39;c&#39;: 3}<\/p>\n<p>value_to_find = 2<\/p>\n<h2><strong>\u67e5\u627e\u503c\u5bf9\u5e94\u7684\u952e<\/strong><\/h2>\n<p>key = find_key_by_value(my_dict, value_to_find)<\/p>\n<p>print(f&quot;Value {value_to_find} corresponds to key &#39;{key}&#39;&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u4ee3\u7801\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u5982\u4f55\u901a\u8fc7\u904d\u5386\u5b57\u5178\u7684\u952e\u503c\u5bf9\uff0c\u627e\u5230\u4e0e\u6307\u5b9a\u503c\u5339\u914d\u7684\u952e\u5e76\u8fd4\u56de\u3002<\/p>\n<\/p>\n<p><h4>2. \u591a\u503c\u5339\u914d<\/h4>\n<\/p>\n<p><p>\u5f53\u5b57\u5178\u4e2d\u53ef\u80fd\u5b58\u5728\u591a\u4e2a\u76f8\u540c\u7684\u503c\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u8fd4\u56de\u6240\u6709\u5339\u914d\u7684\u952e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def find_keys_by_value(d, value):<\/p>\n<p>    keys = [k for k, v in d.items() if v == value]<\/p>\n<p>    return keys<\/p>\n<h2><strong>\u793a\u4f8b\u5b57\u5178<\/strong><\/h2>\n<p>my_dict = {&#39;a&#39;: 1, &#39;b&#39;: 2, &#39;c&#39;: 2, &#39;d&#39;: 3}<\/p>\n<p>value_to_find = 2<\/p>\n<h2><strong>\u67e5\u627e\u503c\u5bf9\u5e94\u7684\u6240\u6709\u952e<\/strong><\/h2>\n<p>keys = find_keys_by_value(my_dict, value_to_find)<\/p>\n<p>print(f&quot;Value {value_to_find} corresponds to keys {keys}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<code>find_keys_by_value<\/code> \u51fd\u6570\u8fd4\u56de\u4e86\u6240\u6709\u4e0e\u6307\u5b9a\u503c\u5339\u914d\u7684\u952e\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u5b57\u5178\u63a8\u5bfc\u5f0f<\/h3>\n<\/p>\n<p><p>\u5b57\u5178\u63a8\u5bfc\u5f0f\u662f\u4e00\u79cd\u66f4\u7b80\u6d01\u7684\u65b9\u6cd5\uff0c\u901a\u8fc7\u5b57\u5178\u63a8\u5bfc\u5f0f\u53ef\u4ee5\u76f4\u63a5\u751f\u6210\u4e00\u4e2a\u53cd\u8f6c\u7684\u5b57\u5178\uff0c\u7136\u540e\u67e5\u627e\u5bf9\u5e94\u7684\u952e\u3002<\/p>\n<\/p>\n<p><h4>1. \u57fa\u672c\u793a\u4f8b<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">def reverse_dict(d):<\/p>\n<p>    return {v: k for k, v in d.items()}<\/p>\n<h2><strong>\u793a\u4f8b\u5b57\u5178<\/strong><\/h2>\n<p>my_dict = {&#39;a&#39;: 1, &#39;b&#39;: 2, &#39;c&#39;: 3}<\/p>\n<h2><strong>\u53cd\u8f6c\u5b57\u5178<\/strong><\/h2>\n<p>reversed_dict = reverse_dict(my_dict)<\/p>\n<p>value_to_find = 2<\/p>\n<h2><strong>\u67e5\u627e\u503c\u5bf9\u5e94\u7684\u952e<\/strong><\/h2>\n<p>key = reversed_dict.get(value_to_find)<\/p>\n<p>print(f&quot;Value {value_to_find} corresponds to key &#39;{key}&#39;&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u6cd5\uff0c\u6211\u4eec\u9996\u5148\u751f\u6210\u4e86\u4e00\u4e2a\u53cd\u8f6c\u7684\u5b57\u5178\uff0c\u7136\u540e\u76f4\u63a5\u4f7f\u7528\u53cd\u8f6c\u5b57\u5178\u67e5\u627e\u503c\u5bf9\u5e94\u7684\u952e\u3002<\/p>\n<\/p>\n<p><h4>2. \u5904\u7406\u91cd\u590d\u503c<\/h4>\n<\/p>\n<p><p>\u5f53\u5b57\u5178\u4e2d\u5b58\u5728\u91cd\u590d\u503c\u65f6\uff0c\u5b57\u5178\u63a8\u5bfc\u5f0f\u751f\u6210\u7684\u53cd\u8f6c\u5b57\u5178\u4f1a\u4e22\u5931\u4e00\u4e9b\u6570\u636e\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 <code>defaultdict<\/code> \u6765\u5904\u7406\u8fd9\u79cd\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from collections import defaultdict<\/p>\n<p>def reverse_dict_with_duplicates(d):<\/p>\n<p>    reversed_dict = defaultdict(list)<\/p>\n<p>    for k, v in d.items():<\/p>\n<p>        reversed_dict[v].append(k)<\/p>\n<p>    return reversed_dict<\/p>\n<h2><strong>\u793a\u4f8b\u5b57\u5178<\/strong><\/h2>\n<p>my_dict = {&#39;a&#39;: 1, &#39;b&#39;: 2, &#39;c&#39;: 2, &#39;d&#39;: 3}<\/p>\n<h2><strong>\u53cd\u8f6c\u5b57\u5178<\/strong><\/h2>\n<p>reversed_dict = reverse_dict_with_duplicates(my_dict)<\/p>\n<p>value_to_find = 2<\/p>\n<h2><strong>\u67e5\u627e\u503c\u5bf9\u5e94\u7684\u6240\u6709\u952e<\/strong><\/h2>\n<p>keys = reversed_dict.get(value_to_find)<\/p>\n<p>print(f&quot;Value {value_to_find} corresponds to keys {keys}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u4f7f\u7528 <code>defaultdict<\/code> \u6765\u5904\u7406\u91cd\u590d\u503c\uff0c\u6bcf\u4e2a\u503c\u5bf9\u5e94\u4e00\u4e2a\u952e\u5217\u8868\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u53cd\u8f6c\u5b57\u5178<\/h3>\n<\/p>\n<p><p>\u53cd\u8f6c\u5b57\u5178\u662f\u53e6\u4e00\u79cd\u5e38\u89c1\u7684\u65b9\u6cd5\uff0c\u901a\u8fc7\u521b\u5efa\u4e00\u4e2a\u503c\u5230\u952e\u7684\u6620\u5c04\u6765\u5b9e\u73b0\u67e5\u627e\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u5b57\u5178\u4e0d\u9891\u7e41\u53d8\u5316\u7684\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><h4>1. \u57fa\u672c\u793a\u4f8b<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">def reverse_dict(d):<\/p>\n<p>    return {v: k for k, v in d.items()}<\/p>\n<h2><strong>\u793a\u4f8b\u5b57\u5178<\/strong><\/h2>\n<p>my_dict = {&#39;a&#39;: 1, &#39;b&#39;: 2, &#39;c&#39;: 3}<\/p>\n<h2><strong>\u53cd\u8f6c\u5b57\u5178<\/strong><\/h2>\n<p>reversed_dict = reverse_dict(my_dict)<\/p>\n<p>print(reversed_dict)<\/p>\n<h2><strong>\u67e5\u627e\u503c\u5bf9\u5e94\u7684\u952e<\/strong><\/h2>\n<p>value_to_find = 2<\/p>\n<p>key = reversed_dict.get(value_to_find)<\/p>\n<p>print(f&quot;Value {value_to_find} corresponds to key &#39;{key}&#39;&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u53cd\u8f6c\u5b57\u5178\uff0c\u6211\u4eec\u53ef\u4ee5\u66f4\u9ad8\u6548\u5730\u67e5\u627e\u503c\u5bf9\u5e94\u7684\u952e\u3002<\/p>\n<\/p>\n<p><h4>2. \u5904\u7406\u91cd\u590d\u503c<\/h4>\n<\/p>\n<p><p>\u4e0e\u5b57\u5178\u63a8\u5bfc\u5f0f\u7c7b\u4f3c\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 <code>defaultdict<\/code> \u6765\u5904\u7406\u5b57\u5178\u4e2d\u7684\u91cd\u590d\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from collections import defaultdict<\/p>\n<p>def reverse_dict_with_duplicates(d):<\/p>\n<p>    reversed_dict = defaultdict(list)<\/p>\n<p>    for k, v in d.items():<\/p>\n<p>        reversed_dict[v].append(k)<\/p>\n<p>    return reversed_dict<\/p>\n<h2><strong>\u793a\u4f8b\u5b57\u5178<\/strong><\/h2>\n<p>my_dict = {&#39;a&#39;: 1, &#39;b&#39;: 2, &#39;c&#39;: 2, &#39;d&#39;: 3}<\/p>\n<h2><strong>\u53cd\u8f6c\u5b57\u5178<\/strong><\/h2>\n<p>reversed_dict = reverse_dict_with_duplicates(my_dict)<\/p>\n<p>print(reversed_dict)<\/p>\n<h2><strong>\u67e5\u627e\u503c\u5bf9\u5e94\u7684\u6240\u6709\u952e<\/strong><\/h2>\n<p>value_to_find = 2<\/p>\n<p>keys = reversed_dict.get(value_to_find)<\/p>\n<p>print(f&quot;Value {value_to_find} corresponds to keys {keys}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u786e\u4fdd\u4e86\u6bcf\u4e2a\u503c\u5bf9\u5e94\u4e00\u4e2a\u952e\u5217\u8868\uff0c\u9002\u7528\u4e8e\u5b57\u5178\u4e2d\u5b58\u5728\u91cd\u590d\u503c\u7684\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528\u751f\u6210\u5668\u8868\u8fbe\u5f0f<\/h3>\n<\/p>\n<p><p>\u751f\u6210\u5668\u8868\u8fbe\u5f0f\u662f\u4e00\u79cd\u9ad8\u6548\u7684\u65b9\u6cd5\uff0c\u9002\u7528\u4e8e\u9700\u8981\u5ef6\u8fdf\u8ba1\u7b97\u7684\u60c5\u51b5\u3002\u901a\u8fc7\u751f\u6210\u5668\u8868\u8fbe\u5f0f\u53ef\u4ee5\u9010\u4e2a\u751f\u6210\u6ee1\u8db3\u6761\u4ef6\u7684\u952e\uff0c\u907f\u514d\u4e00\u6b21\u6027\u52a0\u8f7d\u6240\u6709\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h4>1. \u57fa\u672c\u793a\u4f8b<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">def find_keys_by_value_gen(d, value):<\/p>\n<p>    return (k for k, v in d.items() if v == value)<\/p>\n<h2><strong>\u793a\u4f8b\u5b57\u5178<\/strong><\/h2>\n<p>my_dict = {&#39;a&#39;: 1, &#39;b&#39;: 2, &#39;c&#39;: 2, &#39;d&#39;: 3}<\/p>\n<p>value_to_find = 2<\/p>\n<h2><strong>\u67e5\u627e\u503c\u5bf9\u5e94\u7684\u6240\u6709\u952e<\/strong><\/h2>\n<p>keys_gen = find_keys_by_value_gen(my_dict, value_to_find)<\/p>\n<p>for key in keys_gen:<\/p>\n<p>    print(f&quot;Value {value_to_find} corresponds to key &#39;{key}&#39;&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u4f7f\u7528\u751f\u6210\u5668\u8868\u8fbe\u5f0f\u9010\u4e2a\u751f\u6210\u6ee1\u8db3\u6761\u4ef6\u7684\u952e\uff0c\u9002\u7528\u4e8e\u5927\u5b57\u5178\u7684\u5ef6\u8fdf\u8ba1\u7b97\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u5b57\u5178\u4e2d\uff0c\u901a\u8fc7\u503c\u67e5\u627e\u952e\u7684\u65b9\u6cd5\u6709\u591a\u79cd\u9009\u62e9\uff0c\u5305\u62ec<strong>\u8fed\u4ee3\u5b57\u5178\u9879<\/strong>\u3001<strong>\u5b57\u5178\u63a8\u5bfc\u5f0f<\/strong>\u3001<strong>\u53cd\u8f6c\u5b57\u5178<\/strong>\u4ee5\u53ca<strong>\u751f\u6210\u5668\u8868\u8fbe\u5f0f<\/strong>\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u9002\u7528\u7684\u573a\u666f\u548c\u4f18\u52bf\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u8fed\u4ee3\u5b57\u5178\u9879<\/strong>\u9002\u7528\u4e8e\u7b80\u5355\u67e5\u627e\uff0c\u4ee3\u7801\u76f4\u89c2\u6613\u61c2\u3002<\/li>\n<li><strong>\u5b57\u5178\u63a8\u5bfc\u5f0f<\/strong>\u9002\u7528\u4e8e\u751f\u6210\u53cd\u8f6c\u5b57\u5178\uff0c\u7b80\u6d01\u9ad8\u6548\u3002<\/li>\n<li><strong>\u53cd\u8f6c\u5b57\u5178<\/strong>\u9002\u7528\u4e8e\u4e0d\u9891\u7e41\u53d8\u5316\u7684\u5b57\u5178\uff0c\u63d0\u9ad8\u67e5\u627e\u6548\u7387\u3002<\/li>\n<li><strong>\u751f\u6210\u5668\u8868\u8fbe\u5f0f<\/strong>\u9002\u7528\u4e8e\u5927\u5b57\u5178\u7684\u5ef6\u8fdf\u8ba1\u7b97\uff0c\u907f\u514d\u4e00\u6b21\u6027\u52a0\u8f7d\u6240\u6709\u6570\u636e\u3002<\/li>\n<\/ol>\n<p><p>\u6839\u636e\u5b9e\u9645\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u6267\u884c\u6548\u7387\u3002\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5728Python\u5b57\u5178\u4e2d\u901a\u8fc7\u503c\u67e5\u627e\u5bf9\u5e94\u7684\u952e\uff0c\u4ece\u800c\u5b9e\u73b0\u66f4\u590d\u6742\u7684\u6570\u636e\u5904\u7406\u4efb\u52a1\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5728Python\u5b57\u5178\u4e2d\uff0c\u5982\u4f55\u6839\u636e\u503c\u67e5\u627e\u952e\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u5b57\u5178\u662f\u4ee5\u952e-\u503c\u5bf9\u7684\u5f62\u5f0f\u5b58\u50a8\u6570\u636e\u7684\u3002\u82e5\u60f3\u6839\u636e\u67d0\u4e2a\u503c\u67e5\u627e\u76f8\u5e94\u7684\u952e\uff0c\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u904d\u5386\u5b57\u5178\u7684\u6240\u6709\u9879\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5047\u8bbe\u6709\u4e00\u4e2a\u5b57\u5178<code>my_dict = {&#39;a&#39;: 1, &#39;b&#39;: 2, &#39;c&#39;: 1}<\/code>\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u627e\u5230\u6240\u6709\u5bf9\u5e94\u503c\u4e3a1\u7684\u952e\uff1a  <\/p>\n<pre><code class=\"language-python\">keys = [k for k, v in my_dict.items() if v == 1]\nprint(keys)  # \u8f93\u51fa\uff1a[&#39;a&#39;, &#39;c&#39;]\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u4f1a\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u6240\u6709\u5339\u914d\u952e\u7684\u5217\u8868\u3002<\/p>\n<p><strong>\u662f\u5426\u53ef\u4ee5\u5904\u7406\u5b57\u5178\u4e2d\u6709\u591a\u4e2a\u76f8\u540c\u503c\u7684\u60c5\u51b5\uff1f<\/strong><br \/>\u5f53\u5b57\u5178\u4e2d\u5b58\u5728\u591a\u4e2a\u76f8\u540c\u7684\u503c\u65f6\uff0c\u4f7f\u7528\u4e0a\u8ff0\u65b9\u6cd5\u5c06\u4f1a\u8fd4\u56de\u6240\u6709\u4e0e\u8be5\u503c\u5bf9\u5e94\u7684\u952e\u3002\u4f8b\u5982\uff0c\u5982\u679c\u5b57\u5178<code>my_dict<\/code>\u4e2d\u6709\u591a\u4e2a\u952e\u5bf9\u5e94\u76f8\u540c\u7684\u503c\uff0c\u7ed3\u679c\u5217\u8868\u4f1a\u5305\u542b\u6240\u6709\u5bf9\u5e94\u7684\u952e\u3002\u8fd9\u6837\u7684\u673a\u5236\u975e\u5e38\u9002\u5408\u7528\u4e8e\u67e5\u627e\u548c\u5904\u7406\u6709\u91cd\u590d\u503c\u7684\u5b57\u5178\u6570\u636e\u3002<\/p>\n<p><strong>\u5728\u5b57\u5178\u4e2d\u627e\u952e\u7684\u8fc7\u7a0b\u662f\u5426\u4f1a\u5f71\u54cd\u6027\u80fd\uff1f<\/strong><br \/>\u6027\u80fd\u7684\u5f71\u54cd\u4e3b\u8981\u53d6\u51b3\u4e8e\u5b57\u5178\u7684\u5927\u5c0f\u3002\u904d\u5386\u6574\u4e2a\u5b57\u5178\u9700\u8981O(n)\u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u56e0\u6b64\u5728\u5904\u7406\u5927\u578b\u5b57\u5178\u65f6\uff0c\u67e5\u627e\u8fc7\u7a0b\u53ef\u80fd\u4f1a\u53d8\u5f97\u8f83\u6162\u3002\u5982\u679c\u9700\u8981\u9891\u7e41\u6839\u636e\u503c\u67e5\u627e\u952e\uff0c\u8003\u8651\u53cd\u5411\u6784\u5efa\u4e00\u4e2a\u503c\u5230\u952e\u7684\u6620\u5c04\u5b57\u5178\uff0c\u4ee5\u63d0\u9ad8\u67e5\u627e\u6548\u7387\u3002\u8fd9\u79cd\u65b9\u5f0f\u5c06\u663e\u8457\u4f18\u5316\u6027\u80fd\uff0c\u5c24\u5176\u5728\u6570\u636e\u91cf\u8f83\u5927\u7684\u60c5\u51b5\u4e0b\u3002<\/p>\n<p><strong>\u662f\u5426\u6709\u73b0\u6210\u7684\u5e93\u6216\u5de5\u5177\u53ef\u4ee5\u7b80\u5316\u8fd9\u4e2a\u67e5\u627e\u8fc7\u7a0b\uff1f<\/strong><br \/>Python\u7684\u6807\u51c6\u5e93\u5e76\u672a\u63d0\u4f9b\u76f4\u63a5\u6839\u636e\u503c\u67e5\u627e\u952e\u7684\u529f\u80fd\uff0c\u4f46\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u7b2c\u4e09\u65b9\u5e93\uff0c\u4f8b\u5982<code>pandas<\/code>\uff0c\u5b83\u63d0\u4f9b\u4e86\u66f4\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u529f\u80fd\u3002\u501f\u52a9<code>pandas<\/code>\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06\u5b57\u5178\u8f6c\u6362\u4e3aDataFrame\uff0c\u5e76\u901a\u8fc7\u6761\u4ef6\u8fc7\u6ee4\u5feb\u901f\u67e5\u627e\u76f8\u5e94\u7684\u952e\u3002\u8fd9\u79cd\u65b9\u6cd5\u4e0d\u4ec5\u7b80\u5316\u4e86\u4ee3\u7801\uff0c\u8fd8\u63d0\u9ad8\u4e86\u5904\u7406\u590d\u6742\u6570\u636e\u7684\u7075\u6d3b\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u5b57\u5178\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u503c\u6765\u67e5\u627e\u5bf9\u5e94\u7684\u952e\u3002\u901a\u8fc7\u8fed\u4ee3\u5b57\u5178\u9879\u3001\u4f7f\u7528\u5b57\u5178\u63a8\u5bfc\u5f0f\u3001\u53cd\u8f6c\u5b57\u5178\u7b49\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u8fd9\u4e00\u70b9\u3002 [&hellip;]","protected":false},"author":3,"featured_media":1075868,"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\/1075862"}],"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=1075862"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1075862\/revisions"}],"predecessor-version":[{"id":1075875,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1075862\/revisions\/1075875"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1075868"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1075862"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1075862"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1075862"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}