{"id":205090,"date":"2025-05-29T15:59:09","date_gmt":"2025-05-29T07:59:09","guid":{"rendered":"https:\/\/server.hk\/cnblog\/205090\/"},"modified":"2025-05-29T15:59:09","modified_gmt":"2025-05-29T07:59:09","slug":"%e5%a6%82%e4%bd%95%e4%bb%8e%e4%b8%a4%e4%b8%aa%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84%e4%b8%ad%e6%8f%90%e5%8f%96%e7%89%b9%e5%ae%9a%e6%95%b0%e6%8d%ae%e5%b9%b6%e6%9e%84%e5%bb%ba%e6%96%b0%e7%9a%84%e6%95%b0","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/205090\/","title":{"rendered":"\u5982\u4f55\u4ece\u4e24\u4e2a\u6570\u636e\u7ed3\u6784\u4e2d\u63d0\u53d6\u7279\u5b9a\u6570\u636e\u5e76\u6784\u5efa\u65b0\u7684\u6570\u636e\u7ed3\u6784\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u4ece\u4e24\u4e2a\u6570\u636e\u7ed3\u6784\u4e2d\u63d0\u53d6\u7279\u5b9a\u6570\u636e\u5e76\u6784\u5efa\u65b0\u7684\u6570\u636e\u7ed3\u6784\uff1f<\/h1>\n<p>\u79ef\u7d2f\u77e5\u8bc6\uff0c\u80dc\u8fc7\u79ef\u84c4\u91d1\u94f6\uff01\u6bd5\u7adf\u5728\u6587\u7ae0\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4f1a\u9047\u5230\u5404\u79cd\u5404\u6837\u7684\u95ee\u9898\uff0c\u5f80\u5f80\u90fd\u662f\u4e00\u4e9b\u7ec6\u8282\u77e5\u8bc6\u70b9\u8fd8\u6ca1\u6709\u638c\u63e1\u597d\u800c\u5bfc\u81f4\u7684\uff0c\u56e0\u6b64\u57fa\u7840\u77e5\u8bc6\u70b9\u7684\u79ef\u7d2f\u662f\u5f88\u91cd\u8981\u7684\u3002\u4e0b\u9762\u672c\u6587\u300a\u5982\u4f55\u4ece\u4e24\u4e2a\u6570\u636e\u7ed3\u6784\u4e2d\u63d0\u53d6\u7279\u5b9a\u6570\u636e\u5e76\u6784\u5efa\u65b0\u7684\u6570\u636e\u7ed3\u6784\uff1f\u300b\uff0c\u5c31\u5e26\u5927\u5bb6\u8bb2\u89e3\u4e00\u4e0b\u77e5\u8bc6\u70b9\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241123\/173233822967416235542e1.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u5982\u4f55\u4ece\u7ed9\u5b9a\u6570\u636e\u7ed3\u6784\u4e2d\u83b7\u53d6\u7279\u5b9a\u6570\u636e\u7ed3\u6784<\/strong><\/p>\n<p>\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u9700\u8981\u6839\u636e\u7ed9\u5b9a\u7684\u793a\u4f8b\u6570\u636e\u7ed3\u6784 data1 \u548c data2 \u6765\u83b7\u53d6\u6240\u9700\u7684 result \u6570\u636e\u7ed3\u6784\u3002\u5177\u4f53\u800c\u8a00\uff0c\u6211\u4eec\u9700\u8981\u6839\u636e data1 \u4e2d\u7f16\u53f7 c \u7684\u503c\u5728 data2 \u4e2d\u67e5\u627e\u5bf9\u5e94\u7684\u503c\uff0c\u5e76\u5c06\u5177\u6709\u76f8\u540c\u7f16\u53f7 c \u7684\u7f16\u53f7 a \u4f5c\u4e3a\u952e\uff0c\u5bf9\u5e94\u7684\u7f16\u53f7 d \u4f5c\u4e3a\u503c\uff0c\u8fd4\u56de\u5230 result \u4e2d\u3002<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\uff1a<\/p>\n<pre>result = {}\n\nfor i in data1:\n    A, C, D = i['\u7f16\u53f7A'], i['\u7f16\u53f7C'], i['\u7f16\u53f7D']\n    if C in data2 and D in data2[C]:\n        result.setdefault(A, []).append(D)<\/pre>\n<p>\u5728\u793a\u4f8b\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u904d\u5386 data1 \u4e2d\u7684\u6bcf\u4e2a\u5b57\u5178 i\uff0c\u5e76\u63d0\u53d6\u7f16\u53f7 a\u3001c \u548c d \u7684\u503c\u3002\u5982\u679c\u7f16\u53f7 c \u5728 data2 \u4e2d\u5e76\u4e14\u7f16\u53f7 d \u5728 data2[c] \u4e2d\uff0c\u6211\u4eec\u5c31\u4f1a\u5728 result \u4e2d\u5c06\u7f16\u53f7 a \u6dfb\u52a0\u4e3a\u952e\uff0c\u7f16\u53f7 d \u6dfb\u52a0\u4e3a\u503c\u3002<\/p>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u4ece data1 \u548c data2 \u4e2d\u83b7\u53d6\u6240\u9700\u7684 result \u6570\u636e\u7ed3\u6784\u3002<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8be5\u4ee3\u7801\u5047\u8bbe data2 \u4e2d\u7684\u503c\u662f\u4e00\u4e2a\u5305\u542b\u7f16\u53f7 d \u503c\u7684\u5217\u8868\u3002\u5982\u679c data2 \u4e2d\u7684\u503c\u683c\u5f0f\u4e0d\u540c\uff0c\u5219\u4ee3\u7801\u9700\u8981\u8fdb\u884c\u76f8\u5e94\u7684\u8c03\u6574\u3002<\/p>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300a\u5982\u4f55\u4ece\u4e24\u4e2a\u6570\u636e\u7ed3\u6784\u4e2d\u63d0\u53d6\u7279\u5b9a\u6570\u636e\u5e76\u6784\u5efa\u65b0\u7684\u6570\u636e\u7ed3\u6784\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\u516c\u4f17\u53f7\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4ece\u4e24\u4e2a\u6570\u636e\u7ed3\u6784\u4e2d\u63d0\u53d6\u7279\u5b9a\u6570\u636e&#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-205090","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205090","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=205090"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205090\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=205090"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=205090"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=205090"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}