{"id":50702,"date":"2024-12-03T17:47:45","date_gmt":"2024-12-03T09:47:45","guid":{"rendered":"https:\/\/fwq.ai\/blog\/50702\/"},"modified":"2024-12-03T17:47:45","modified_gmt":"2024-12-03T09:47:45","slug":"%e5%a6%82%e4%bd%95%e9%80%9a%e8%bf%87%e5%ad%97%e7%ac%a6%e4%b8%b2%e4%b8%ad%e7%9a%84%e6%95%b0%e5%ad%97%e5%af%b9-python-%e5%88%97%e8%a1%a8%e8%bf%9b%e8%a1%8c%e6%8e%92%e5%ba%8f%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/50702\/","title":{"rendered":"\u5982\u4f55\u901a\u8fc7\u5b57\u7b26\u4e32\u4e2d\u7684\u6570\u5b57\u5bf9 Python \u5217\u8868\u8fdb\u884c\u6392\u5e8f\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u901a\u8fc7\u5b57\u7b26\u4e32\u4e2d\u7684\u6570\u5b57\u5bf9 Python \u5217\u8868\u8fdb\u884c\u6392\u5e8f\uff1f<\/h1>\n<p>\u5bf9\u4e8e\u4e00\u4e2a\u6587\u7ae0\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u7262\u56fa\u624e\u5b9e\u7684\u57fa\u7840\u662f\u5341\u5206\u91cd\u8981\u7684\uff0c\u7c73\u4e91\u5c31\u6765\u5e26\u5927\u5bb6\u4e00\u70b9\u70b9\u7684\u638c\u63e1\u57fa\u7840\u77e5\u8bc6\u70b9\u3002\u4eca\u5929\u672c\u7bc7\u6587\u7ae0\u5e26\u5927\u5bb6\u4e86\u89e3\u300a\u5982\u4f55\u901a\u8fc7\u5b57\u7b26\u4e32\u4e2d\u7684\u6570\u5b57\u5bf9 Python \u5217\u8868\u8fdb\u884c\u6392\u5e8f\uff1f\u300b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e86\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u5feb\u70b9\u6536\u85cf\u8d77\u6765\u5427\uff0c\u5426\u5219\u9700\u8981\u65f6\u5c31\u627e\u4e0d\u5230\u4e86\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241125\/173254648067448fb05753c.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u901a\u8fc7\u5b57\u7b26\u4e32\u4e2d\u7684\u6570\u5b57\u5bf9 Python \u5217\u8868\u8fdb\u884c\u6392\u5e8f\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u901a\u8fc7\u5b57\u7b26\u4e32\u4e2d\u7684\u6570\u5b57\u5bf9 Python \u5217\u8868\u8fdb\u884c\u6392\u5e8f\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u901a\u8fc7\u5b57\u7b26\u4e32\u4e2d\u7684\u6570\u5b57\u5bf9 python \u5217\u8868\u8fdb\u884c\u6392\u5e8f<\/strong><\/p>\n<p>\u5bf9\u5305\u542b\u4e2d\u6587\u6216\u963f\u62c9\u4f2f\u6570\u5b57\u7684\u5b57\u7b26\u4e32\u8fdb\u884c\u6392\u5e8f\u662f\u4e00\u9879\u5e38\u89c1\u7684\u4efb\u52a1\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5b9e\u73b0\u6b64\u76ee\u6807\u7684 python \u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<pre>import re\n\nmap = {\n    '\u4e00': 1,\n    '\u4e8c': 2,\n    '\u4e09': 3,\n    '\u56db': 4,\n    '\u4e94': 5,\n}\n\n# \u6d4b\u8bd5\u6570\u636e\ndata = [\n    ('\u6d4b\u8bd5\u6587\u672c', '\u7b2c\u4e8c\u5b63 \u7b2c2\u96c6'),\n    ('\u6d4b\u8bd5\u6587\u672c', '\u7b2c1\u5b63 \u7b2c\u4e00\u96c6'),\n    ('\u6d4b\u8bd5\u6587\u672c', '\u7b2c1\u5b63 \u7b2c2\u96c6'),\n    ('\u6d4b\u8bd5\u6587\u672c', '\u7b2c\u4e8c\u5b63 \u7b2c1\u96c6'),\n]\n\nres = dict()\nfor item in data:\n    pattern = re.compile(r'\u7b2c(.*)\u5b63 \u7b2c(.*)\u96c6')\n    result = pattern.findall(str(item))[0]\n\n    k1 = int(map[result[0]]) * 10 if result[0] in map.keys() else int(result[0]) * 10\n    k2 = int(map[result[1]]) if result[1] in map.keys() else int(result[1])\n\n    res[k1 + k2] = item\n\nresult = sorted(res.items(), key=lambda x: x[0])\nprint(result)<\/pre>\n<p>\u8fd9\u4e2a\u811a\u672c\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u4ece\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u5b63\u6570\u548c\u96c6\u6570\u3002\u7136\u540e\u5c06\u8fd9\u4e9b\u6570\u5b57\u8f6c\u6362\u4e3a\u6574\u578b\uff0c\u5176\u4e2d\u5b63\u6570\u4e58\u4ee5 10 \u4ee5\u786e\u4fdd\u5728\u6bd4\u8f83\u4e2d\u5177\u6709\u66f4\u9ad8\u7684\u4f18\u5148\u7ea7\u3002\u6700\u540e\uff0c\u6570\u636e\u4f5c\u4e3a\u952e\u503c\u5bf9\u5b58\u50a8\u5728\u4e00\u4e2a\u5b57\u5178\u4e2d\uff0c\u5e76\u6839\u636e\u952e\u8fdb\u884c\u6392\u5e8f\u3002\u6392\u5e8f\u540e\u7684\u7ed3\u679c\u662f\u4e00\u4e2a\u6709\u5e8f\u5143\u7ec4\u5217\u8868\uff0c\u5176\u4e2d\u5305\u542b\u539f\u59cb\u5b57\u7b26\u4e32\u548c\u63d0\u53d6\u7684\u6570\u5b57\u3002<\/p>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8e\u6587\u7ae0\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u901a\u8fc7\u5b57\u7b26\u4e32\u4e2d\u7684\u6570\u5b57\u5bf9 Python \u5217\u8868\u8fdb\u884c\u6392\u5e8f\uff1f \u5bf9\u4e8e\u4e00\u4e2a\u6587\u7ae0\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u7262\u56fa\u624e\u5b9e\u7684\u57fa\u7840\u662f\u5341\u5206\u91cd\u8981\u7684\uff0c\u7c73\u4e91\u5c31\u6765\u5e26\u5927\u5bb6\u4e00\u70b9\u70b9\u7684\u638c\u63e1\u57fa\u7840\u77e5\u8bc6\u70b9\u3002\u4eca\u5929\u672c\u7bc7\u6587\u7ae0\u5e26\u5927\u5bb6\u4e86\u89e3\u300a\u5982\u4f55\u901a\u8fc7\u5b57\u7b26\u4e32\u4e2d\u7684\u6570\u5b57\u5bf9 Python \u5217\u8868\u8fdb\u884c\u6392\u5e8f\uff1f\u300b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e86\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u5feb\u70b9\u6536\u85cf\u8d77\u6765\u5427\uff0c\u5426\u5219\u9700\u8981\u65f6\u5c31\u627e\u4e0d\u5230\u4e86\uff01 \u5982\u4f55\u901a\u8fc7\u5b57\u7b26\u4e32\u4e2d\u7684\u6570\u5b57\u5bf9 python \u5217\u8868\u8fdb\u884c\u6392\u5e8f \u5bf9\u5305\u542b\u4e2d\u6587\u6216\u963f\u62c9\u4f2f\u6570\u5b57\u7684\u5b57\u7b26\u4e32\u8fdb\u884c\u6392\u5e8f\u662f\u4e00\u9879\u5e38\u89c1\u7684\u4efb\u52a1\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5b9e\u73b0\u6b64\u76ee\u6807\u7684 python \u89e3\u51b3\u65b9\u6848\uff1a import re map = { &#8216;\u4e00&#8217;: 1, &#8216;\u4e8c&#8217;: 2, &#8216;\u4e09&#8217;: 3, &#8216;\u56db&#8217;: 4, &#8216;\u4e94&#8217;: 5, } # \u6d4b\u8bd5\u6570\u636e data = [ (&#8216;\u6d4b\u8bd5\u6587\u672c&#8217;, &#8216;\u7b2c\u4e8c\u5b63 \u7b2c2\u96c6&#8217;), (&#8216;\u6d4b\u8bd5\u6587\u672c&#8217;, &#8216;\u7b2c1\u5b63 \u7b2c\u4e00\u96c6&#8217;), (&#8216;\u6d4b\u8bd5\u6587\u672c&#8217;, &#8216;\u7b2c1\u5b63 \u7b2c2\u96c6&#8217;), (&#8216;\u6d4b\u8bd5\u6587\u672c&#8217;, &#8216;\u7b2c\u4e8c\u5b63 \u7b2c1\u96c6&#8217;), ] res = dict() for item in data: pattern = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-50702","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/50702","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=50702"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/50702\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=50702"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=50702"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=50702"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}