{"id":204154,"date":"2025-05-29T12:26:55","date_gmt":"2025-05-29T04:26:55","guid":{"rendered":"https:\/\/server.hk\/cnblog\/204154\/"},"modified":"2025-05-29T12:26:55","modified_gmt":"2025-05-29T04:26:55","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-python-%e4%bb%a3%e7%a0%81%e5%b0%86%e5%85%b7%e6%9c%89%e7%9b%b8%e5%90%8c%e5%89%8d%e4%b8%89%e4%b8%aa%e5%85%83%e7%b4%a0%e7%9a%84%e5%a4%9a%e4%b8%aa%e5%88%97%e8%a1%a8","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/204154\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 Python \u4ee3\u7801\u5c06\u5177\u6709\u76f8\u540c\u524d\u4e09\u4e2a\u5143\u7d20\u7684\u591a\u4e2a\u5217\u8868\u5408\u5e76\u4e3a\u4e00\u4e2a\u65b0\u7684\u5217\u8868\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u4f7f\u7528 Python \u4ee3\u7801\u5c06\u5177\u6709\u76f8\u540c\u524d\u4e09\u4e2a\u5143\u7d20\u7684\u591a\u4e2a\u5217\u8868\u5408\u5e76\u4e3a\u4e00\u4e2a\u65b0\u7684\u5217\u8868\uff1f<\/h1>\n<p>\u77e5\u8bc6\u70b9\u638c\u63e1\u4e86\uff0c\u8fd8\u9700\u8981\u4e0d\u65ad\u7ec3\u4e60\u624d\u80fd\u719f\u7ec3\u8fd0\u7528\u3002\u4e0b\u9762\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u4e2a\u6587\u7ae0\u5f00\u53d1\u5b9e\u6218\uff0c\u624b\u628a\u624b\u6559\u5927\u5bb6\u5b66\u4e60\u300a\u5982\u4f55\u4f7f\u7528 Python \u4ee3\u7801\u5c06\u5177\u6709\u76f8\u540c\u524d\u4e09\u4e2a\u5143\u7d20\u7684\u591a\u4e2a\u5217\u8868\u5408\u5e76\u4e3a\u4e00\u4e2a\u65b0\u7684\u5217\u8868\uff1f\u300b\uff0c\u5728\u5b9e\u73b0\u529f\u80fd\u7684\u8fc7\u7a0b\u4e2d\u4e5f\u5e26\u5927\u5bb6\u91cd\u65b0\u6e29\u4e60\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6e29\u6545\u800c\u77e5\u65b0\uff0c\u56de\u5934\u770b\u770b\u8bf4\u4e0d\u5b9a\u53c8\u6709\u4e0d\u4e00\u6837\u7684\u611f\u609f\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241030\/17302649796721bf935f71f.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u5c06\u524d\u4e09\u4e2a\u5143\u7d20\u7528\u4f5c\u952e\u5408\u5e76\u591a\u4e2a\u5217\u8868<\/strong><\/p>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u5217\u8868 o\uff0c\u5176\u5305\u542b\u591a\u4e2a\u5185\u90e8\u5217\u8868\uff0c\u6bcf\u4e2a\u5185\u90e8\u5217\u8868\u5177\u6709\u56db\u4e2a\u5143\u7d20\uff1acmd\u3001opt\u3001xx.x(x)se \u548c catxxxx\u3002\u76ee\u6807\u662f\u5c06 o \u4e2d\u524d\u4e09\u4e2a\u5143\u7d20\uff08cmd\u3001opt \u548c xx.x(x)se\uff09\u7528\u4f5c\u952e\uff0c\u5e76\u5c06\u5177\u6709\u76f8\u540c\u952e\u7684\u5217\u8868\u7684\u7b2c\u56db\u4e2a\u5143\u7d20\u5408\u5e76\u4e3a\u4e00\u4e2a\u5217\u8868\u3002<\/p>\n<p>\u4ee5\u4e0b python \u4ee3\u7801\u63d0\u4f9b\u4e86\u4e00\u79cd\u65b9\u6cd5\u6765\u5b9e\u73b0\u6b64\u76ee\u6807\uff1a<\/p>\n<pre>def combine_list(list1, list2):\n    list0 = list1[:]\n    if list1[0] == list2[0] and list1[1] == list2[1] and list1[2] == list2[2]:\n        list_temp = [list1[3], list2[3]]\n        list0[3] = list_temp\n        return list0\n    else:\n        pass\n\no = []\na = ['cmd', ['opt1', 'opt2'], '12.2(2)SE', 'Cat3560']\nb = ['cmd', ['opt1', 'opt2'], '12.2(2)SE', 'Cat4500']\nc = ['cmd', ['opt1', 'opt2', 'opt3', 'opt4'], '12.3(2)SE', 'Cat3560']\nd = ['cmd', ['opt1', 'opt2', 'opt3'], '12.4(2)SE', 'Cat3560']\no.append(a)\no.append(b)\no.append(c)\no.append(d)\n\no_new = o[:]\n\ni = 1\nj = 0\nfor i in range(i, len(o)):\n    temp = combine_list(o[j], o[i])\n    if temp is not None:\n        o_new.append(temp)\n        o_new.remove(o[j])\n        o_new.remove(o[i])\n    if i == 3:\n        j += 1\n        i = 1\n    if j == 3:\n        break\nprint(o_new)<\/pre>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300a\u5982\u4f55\u4f7f\u7528 Python \u4ee3\u7801\u5c06\u5177\u6709\u76f8\u540c\u524d\u4e09\u4e2a\u5143\u7d20\u7684\u591a\u4e2a\u5217\u8868\u5408\u5e76\u4e3a\u4e00\u4e2a\u65b0\u7684\u5217\u8868\uff1f\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528 Python \u4ee3\u7801\u5c06\u5177&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-204154","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204154","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=204154"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204154\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=204154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=204154"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=204154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}