{"id":49547,"date":"2024-12-03T17:25:37","date_gmt":"2024-12-03T09:25:37","guid":{"rendered":"https:\/\/fwq.ai\/blog\/49547\/"},"modified":"2024-12-03T17:25:37","modified_gmt":"2024-12-03T09:25:37","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-python-%e5%af%b9%e5%85%83%e7%bb%84%e5%88%97%e8%a1%a8%e6%8c%89%e7%85%a7%e7%ac%ac%e4%b8%80%e4%b8%aa%e5%85%83%e7%b4%a0%e8%bf%9b%e8%a1%8c%e6%8e%92%e5%ba%8f%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/49547\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 Python \u5bf9\u5143\u7ec4\u5217\u8868\u6309\u7167\u7b2c\u4e00\u4e2a\u5143\u7d20\u8fdb\u884c\u6392\u5e8f\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u4f7f\u7528 Python \u5bf9\u5143\u7ec4\u5217\u8868\u6309\u7167\u7b2c\u4e00\u4e2a\u5143\u7d20\u8fdb\u884c\u6392\u5e8f\uff1f<\/h1>\n<p>\u7c73\u4e91\u4eca\u5929\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u662f\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u6216\u8005\u5df2\u7ecf\u662f\u5927\u4f6c\u7ea7\u522b\u4e86\uff0c\u90fd\u975e\u5e38\u6b22\u8fce\u4e5f\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u7ed9\u6211\u5efa\u8bae\u8bc4\u8bba\u54c8~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729944587671cdc0b1cd2a.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 Python \u5bf9\u5143\u7ec4\u5217\u8868\u6309\u7167\u7b2c\u4e00\u4e2a\u5143\u7d20\u8fdb\u884c\u6392\u5e8f\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 Python \u5bf9\u5143\u7ec4\u5217\u8868\u6309\u7167\u7b2c\u4e00\u4e2a\u5143\u7d20\u8fdb\u884c\u6392\u5e8f\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u6309\u7167\u5143\u7ec4\u7b2c\u4e00\u5143\u7d20\u5bf9\u5143\u7ec4\u5217\u8868\u8fdb\u884c\u6392\u5e8f<\/strong><\/p>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u5143\u7ec4 [(a, b)] \u7684\u5217\u8868 aalist\uff0c\u76ee\u6807\u662f\u5bf9\u5217\u8868\u4e2d\u7684\u5143\u7ec4\u6309\u5176\u7b2c\u4e00\u4e2a\u5143\u7d20 a \u8fdb\u884c\u5347\u5e8f\u6392\u5217\u3002<\/p>\n<p><strong>\u6392\u5e8f\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>\u4f7f\u7528 python \u5185\u7f6e\u7684 sorted() \u51fd\u6570\u3002\u8be5\u51fd\u6570\u63a5\u53d7\u4e00\u4e2a\u5217\u8868\u548c\u4e00\u4e2a\u952e\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\uff0c\u952e\u51fd\u6570\u7528\u4e8e\u6307\u5b9a\u6392\u5e8f\u89c4\u5219\u3002<\/p>\n<p>\u5bf9\u4e8e\u672c\u4f8b\uff0c\u53ef\u4ee5\u4f7f\u7528 lambda \u8868\u8fbe\u5f0f\u4f5c\u4e3a\u952e\u51fd\u6570\uff0c\u8be5\u8868\u8fbe\u5f0f\u63d0\u53d6\u5143\u7ec4\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\u3002<\/p>\n<p><strong>\u4ee3\u7801\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>aalist = [(1184, 862), (1034, 871), (968, 848), (910, 834), (716, 832), (594, 872), (594, 872), (855, 834), (796, 837), (1330, 827), (1330, 827), (623, 834)]\n\nsorted_aalist = sorted(aalist, key=lambda _: _[0])\n\nprint(sorted_aalist)<\/pre>\n<p><strong>\u8f93\u51fa\uff1a<\/strong><\/p>\n<pre>[(594, 872), (594, 872), (623, 834), (716, 832), (796, 837), (855, 834), (910, 834), (968, 848), (1034, 871), (1184, 862), (1330, 827), (1330, 827)]<\/pre>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300a\u5982\u4f55\u4f7f\u7528 Python \u5bf9\u5143\u7ec4\u5217\u8868\u6309\u7167\u7b2c\u4e00\u4e2a\u5143\u7d20\u8fdb\u884c\u6392\u5e8f\uff1f\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528 Python \u5bf9\u5143\u7ec4\u5217\u8868\u6309\u7167\u7b2c\u4e00\u4e2a\u5143\u7d20\u8fdb\u884c\u6392\u5e8f\uff1f \u7c73\u4e91\u4eca\u5929\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u662f\u6b63\u5728\u5b66\u4e60\u6587\u7ae0\u6216\u8005\u5df2\u7ecf\u662f\u5927\u4f6c\u7ea7\u522b\u4e86\uff0c\u90fd\u975e\u5e38\u6b22\u8fce\u4e5f\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u7ed9\u6211\u5efa\u8bae\u8bc4\u8bba\u54c8~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\uff01 \u6309\u7167\u5143\u7ec4\u7b2c\u4e00\u5143\u7d20\u5bf9\u5143\u7ec4\u5217\u8868\u8fdb\u884c\u6392\u5e8f \u7ed9\u5b9a\u4e00\u4e2a\u5305\u542b\u5143\u7ec4 [(a, b)] \u7684\u5217\u8868 aalist\uff0c\u76ee\u6807\u662f\u5bf9\u5217\u8868\u4e2d\u7684\u5143\u7ec4\u6309\u5176\u7b2c\u4e00\u4e2a\u5143\u7d20 a \u8fdb\u884c\u5347\u5e8f\u6392\u5217\u3002 \u6392\u5e8f\u65b9\u6cd5\uff1a \u4f7f\u7528 python \u5185\u7f6e\u7684 sorted() \u51fd\u6570\u3002\u8be5\u51fd\u6570\u63a5\u53d7\u4e00\u4e2a\u5217\u8868\u548c\u4e00\u4e2a\u952e\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\uff0c\u952e\u51fd\u6570\u7528\u4e8e\u6307\u5b9a\u6392\u5e8f\u89c4\u5219\u3002 \u5bf9\u4e8e\u672c\u4f8b\uff0c\u53ef\u4ee5\u4f7f\u7528 lambda \u8868\u8fbe\u5f0f\u4f5c\u4e3a\u952e\u51fd\u6570\uff0c\u8be5\u8868\u8fbe\u5f0f\u63d0\u53d6\u5143\u7ec4\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\u3002 \u4ee3\u7801\u793a\u4f8b\uff1a aalist = [(1184, 862), (1034, 871), (968, 848), (910, 834), (716, 832), (594, 872), (594, 872), (855, 834), (796, 837), (1330, 827), (1330, 827), (623, 834)] sorted_aalist = sorted(aalist, key=lambda _: _[0]) print(sorted_aalist) [&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-49547","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49547","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=49547"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49547\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=49547"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=49547"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=49547"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}