{"id":5397,"date":"2022-04-02T20:46:20","date_gmt":"2022-04-02T12:46:20","guid":{"rendered":"https:\/\/egonlin.com\/?p=5397"},"modified":"2022-04-02T20:46:20","modified_gmt":"2022-04-02T12:46:20","slug":"06-01-%e9%9b%86%e5%90%88%e7%b1%bb%e5%9e%8b%e5%8f%8a%e6%93%8d%e4%bd%9c","status":"publish","type":"post","link":"https:\/\/egonlin.com\/?p=5397","title":{"rendered":"06-01 \u96c6\u5408\u7c7b\u578b\u53ca\u64cd\u4f5c"},"content":{"rendered":"<h1>\u4e00\u3001\u6982\u8ff0<\/h1>\n<ul>\n<li>\u96c6\u5408\u7c7b\u578b\u5b9a\u4e49<\/li>\n<li>\u96c6\u5408\u64cd\u4f5c\u7b26<\/li>\n<li>\u96c6\u5408\u5904\u7406\u65b9\u6cd5<\/li>\n<li>\u96c6\u5408\u7c7b\u578b\u5e94\u7528\u573a\u666f<\/li>\n<\/ul>\n<h1>\u4e8c\u3001\u96c6\u5408\u7c7b\u578b\u5b9a\u4e49<\/h1>\n<p>\u96c6\u5408\u662f\u591a\u4e2a\u5143\u7d20\u7684\u65e0\u5e8f\u7ec4\u5408<\/p>\n<ul>\n<li>\u96c6\u5408\u7c7b\u578b\u4e0e\u6570\u5b66\u4e2d\u7684\u96c6\u5408\u6982\u5ff5\u4e00\u81f4<\/li>\n<li>\u96c6\u5408\u5143\u7d20\u4e4b\u95f4\u65e0\u5e8f\uff0c\u6bcf\u4e2a\u5143\u7d20\u552f\u4e00\uff0c\u4e0d\u5b58\u5728\u76f8\u540c\u5143\u7d20<\/li>\n<li>\u96c6\u5408\u5143\u7d20\u4e0d\u53ef\u66f4\u6539\uff0c\u4e0d\u80fd\u662f\u53ef\u53d8\u6570\u636e\u7c7b\u578b<\/li>\n<li>\u96c6\u5408\u7528\u5927\u62ec\u53f7 {} \u8868\u793a\uff0c\u5143\u7d20\u95f4\u7528\u9017\u53f7\u5206\u9694<\/li>\n<li>\u5efa\u7acb\u96c6\u5408\u7c7b\u578b\u7528 {} \u6216 set()<\/li>\n<li>\u5efa\u7acb\u7a7a\u96c6\u5408\u7c7b\u578b\uff0c\u5fc5\u987b\u4f7f\u7528set()<\/li>\n<\/ul>\n<pre><code class=\"language-python\">A = {&quot;python&quot;, 123, (&quot;python&quot;, 123)}  # \u4f7f\u7528{}\u5efa\u7acb\u96c6\u5408\nA\n{(&#039;python&#039;, 123), 123, &#039;python&#039;}\nB = set(&quot;pypy123&quot;)  # \u4f7f\u7528set()\u5efa\u7acb\u96c6\u5408\nB\n{&#039;1&#039;, &#039;2&#039;, &#039;3&#039;, &#039;p&#039;, &#039;y&#039;}\nC = {&quot;python&quot;, 123, &quot;python&quot;, 123}\nC\n{123, &#039;python&#039;}<\/code><\/pre>\n<h1>\u4e09\u3001\u96c6\u5408\u64cd\u4f5c\u7b26<\/h1>\n<h2>3.1 \u96c6\u5408\u95f4\u64cd\u4f5c<\/h2>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/egonlin.com\/wp-content\/uploads\/2022\/04\/\u96c6\u5408\u7c7b\u578b\u53ca\u64cd\u4f5c1.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"https:\/\/egonlin.com\/wp-content\/uploads\/2022\/04\/\u96c6\u5408\u7c7b\u578b\u53ca\u64cd\u4f5c1.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<h2>3.2 6\u4e2a\u64cd\u4f5c\u7b26<\/h2>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u64cd\u4f5c\u7b26\u53ca\u5e94\u7528<\/th>\n<th style=\"text-align: center;\">\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">S | T<\/td>\n<td style=\"text-align: center;\">\u8fd4\u56de\u4e00\u4e2a\u65b0\u96c6\u5408\uff0c\u5305\u62ec\u5728\u96c6\u5408S\u548cT\u4e2d\u7684\u6240\u6709\u5143\u7d20<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">S &#8211; T<\/td>\n<td style=\"text-align: center;\">\u8fd4\u56de\u4e00\u4e2a\u65b0\u96c6\u5408\uff0c\u5305\u62ec\u5728\u96c6\u5408S\u4f46\u4e0d\u5728T\u4e2d\u7684\u5143\u7d20<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">S &amp; T<\/td>\n<td style=\"text-align: center;\">\u8fd4\u56de\u4e00\u4e2a\u65b0\u96c6\u5408\uff0c\u5305\u62ec\u540c\u65f6\u5728\u96c6\u5408S\u548cT\u4e2d\u7684\u5143\u7d20<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">S ^ T<\/td>\n<td style=\"text-align: center;\">\u8fd4\u56de\u4e00\u4e2a\u65b0\u96c6\u5408\uff0c\u5305\u62ec\u96c6\u5408S\u548cT\u4e2d\u7684\u975e\u76f8\u540c\u5143\u7d20<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">S &lt;= T\u6216S &lt; T<\/td>\n<td style=\"text-align: center;\">\u8fd4\u56deTrue\/False\uff0c\u5224\u65adS\u548cT\u7684\u5b50\u96c6\u5173\u7cfb<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">S &gt;= T\u6216S &gt; T<\/td>\n<td style=\"text-align: center;\">\u8fd4\u56deTrue\/False\uff0c\u5224\u65adS\u548cT\u7684\u5305\u542b\u5173\u7cfb<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>3.3 4\u4e2a\u589e\u5f3a\u64cd\u4f5c\u7b26<\/h2>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u64cd\u4f5c\u7b26\u53ca\u5e94\u7528<\/th>\n<th style=\"text-align: center;\">\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">S |= T<\/td>\n<td style=\"text-align: center;\">\u66f4\u65b0\u96c6\u5408S\uff0c\u5305\u62ec\u5728\u96c6\u5408S\u548cT\u4e2d\u7684\u6240\u6709\u5143\u7d20<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">S -= T<\/td>\n<td style=\"text-align: center;\">\u66f4\u65b0\u96c6\u5408S\uff0c\u5305\u62ec\u5728\u96c6\u5408S\u4f46\u4e0d\u5728T\u4e2d\u7684\u5143\u7d20<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">S &amp;= T<\/td>\n<td style=\"text-align: center;\">\u66f4\u65b0\u96c6\u5408S\uff0c\u5305\u62ec\u540c\u65f6\u5728\u96c6\u5408S\u548cT\u4e2d\u7684\u5143\u7d20<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">S ^= T<\/td>\n<td style=\"text-align: center;\">\u66f4\u65b0\u96c6\u5408S\uff0c\u5305\u62ec\u96c6\u5408S\u548cT\u4e2d\u7684\u975e\u76f8\u540c\u5143\u7d20<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre><code class=\"language-python\">A = {&quot;p&quot;, &quot;y&quot;, 123}\nB = set(&quot;pypy123&quot;)\nA - B\n{123}\nA &amp; B\n{&#039;p&#039;, &#039;y&#039;}\nA ^ B\n{&#039;1&#039;, 123, &#039;2&#039;, &#039;3&#039;}\nB - A\n{&#039;1&#039;, &#039;2&#039;, &#039;3&#039;}\nA | B\n{&#039;1&#039;, 123, &#039;2&#039;, &#039;3&#039;, &#039;p&#039;, &#039;y&#039;}<\/code><\/pre>\n<h1>\u56db\u3001\u96c6\u5408\u5904\u7406\u65b9\u6cd5<\/h1>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u64cd\u4f5c\u51fd\u6570\u6216\u65b9\u6cd5<\/th>\n<th style=\"text-align: center;\">\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">S.add(x)<\/td>\n<td style=\"text-align: center;\">\u5982\u679cx\u4e0d\u5728\u96c6\u5408S\u4e2d\uff0c\u5c06x\u589e\u52a0\u5230S<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">S.discard(x)<\/td>\n<td style=\"text-align: center;\">\u79fb\u9664S\u4e2d\u5143\u7d20x\uff0c\u5982\u679cx\u4e0d\u5728\u96c6\u5408S\u4e2d\uff0c\u4e0d\u62a5\u9519<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">S.remove(x)<\/td>\n<td style=\"text-align: center;\">\u79fb\u9664S\u4e2d\u5143\u7d20x\uff0c\u5982\u679cx\u4e0d\u5728\u96c6\u5408S\u4e2d\uff0c\u4ea7\u751fKeyError\u5f02\u5e38<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">S.clear()<\/td>\n<td style=\"text-align: center;\">\u79fb\u9664S\u4e2d\u6240\u6709\u5143\u7d20<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">S.pop()<\/td>\n<td style=\"text-align: center;\">\u968f\u673a\u8fd4\u56deS\u7684\u4e00\u4e2a\u5143\u7d20\uff0c\u66f4\u65b0S\uff0c\u82e5S\u4e3a\u7a7a\u4ea7\u751fKeyError\u5f02\u5e38<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">S.copy()<\/td>\n<td style=\"text-align: center;\">\u8fd4\u56de\u96c6\u5408S\u7684\u4e00\u4e2a\u526f\u672c<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">len(S)<\/td>\n<td style=\"text-align: center;\">\u8fd4\u56de\u96c6\u5408S\u7684\u5143\u7d20\u4e2a\u6570<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">x in S<\/td>\n<td style=\"text-align: center;\">\u5224\u65adS\u4e2d\u5143\u7d20x\uff0cx\u5728\u96c6\u5408S\u4e2d\uff0c\u8fd4\u56deTrue\uff0c\u5426\u5219\u8fd4\u56deFalse<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">x not in S<\/td>\n<td style=\"text-align: center;\">\u5224\u65adS\u4e2d\u5143\u7d20x\uff0cx\u4e0d\u5728\u96c6\u5408S\u4e2d\uff0c\u8fd4\u56deFalse\uff0c\u5426\u5219\u8fd4\u56deTrue<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">set(x)<\/td>\n<td style=\"text-align: center;\">\u5c06\u5176\u4ed6\u7c7b\u578b\u53d8\u91cfx\u8f6c\u53d8\u4e3a\u96c6\u5408\u7c7b\u578b<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre><code class=\"language-python\">A = {&quot;p&quot;, &quot;y&quot;, 123}\nfor item in A:\n    print(item, end=&quot;&quot;)\n123yp<\/code><\/pre>\n<h1>\u4e94\u3001\u96c6\u5408\u7c7b\u578b\u5e94\u7528\u573a\u666f<\/h1>\n<h2>5.1 \u5305\u542b\u5173\u7cfb\u6bd4\u8f83<\/h2>\n<pre><code class=\"language-python\">&quot;p&quot; in {&quot;p&quot;, &quot;y&quot; , 123}\nTrue\n{&quot;p&quot;, &quot;y&quot;} &gt;= {&quot;p&quot;, &quot;y&quot; , 123}\nFalse<\/code><\/pre>\n<h2>5.2 \u6570\u636e\u53bb\u91cd\uff1a\u96c6\u5408\u7c7b\u578b\u6240\u6709\u5143\u7d20\u65e0\u91cd\u590d<\/h2>\n<pre><code class=\"language-python\">ls = [&quot;p&quot;, &quot;p&quot;, &quot;y&quot;, &quot;y&quot;, 123]\ns = set(ls)   # \u5229\u7528\u4e86\u96c6\u5408\u65e0\u91cd\u590d\u5143\u7d20\u7684\u7279\u70b9\ns\n{123, &#039;p&#039;, &#039;y&#039;}\nlt = list(s)  # \u8fd8\u53ef\u4ee5\u5c06\u96c6\u5408\u8f6c\u6362\u4e3a\u5217\u8868\nlt\n[123, &#039;y&#039;, &#039;p&#039;]<\/code><\/pre>\n<h1>\u516d\u3001\u5c0f\u7ed3<\/h1>\n<ul>\n<li>\u96c6\u5408\u4f7f\u7528{}\u548cset()\u51fd\u6570\u521b\u5efa<\/li>\n<li>\u96c6\u5408\u95f4\u64cd\u4f5c\uff1a\u4ea4(&amp;)\u3001\u5e76(|)\u3001\u5dee(-)\u3001\u8865(^)\u3001\u6bd4\u8f83(&gt;=&lt;)<\/li>\n<li>\u96c6\u5408\u7c7b\u578b\u65b9\u6cd5\uff1a.add()\u3001.discard()\u3001.pop()\u7b49<\/li>\n<li>\u96c6\u5408\u7c7b\u578b\u4e3b\u8981\u5e94\u7528\u4e8e\uff1a\u5305\u542b\u5173\u7cfb\u6bd4\u8f83\u3001\u6570\u636e\u53bb\u91cd<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u6982\u8ff0 \u96c6\u5408\u7c7b\u578b\u5b9a\u4e49 \u96c6\u5408\u64cd\u4f5c\u7b26 \u96c6\u5408\u5904\u7406\u65b9\u6cd5 \u96c6\u5408\u7c7b\u578b\u5e94\u7528\u573a\u666f \u4e8c\u3001\u96c6\u5408\u7c7b\u578b\u5b9a\u4e49 \u96c6\u5408\u662f\u591a\u4e2a\u5143\u7d20\u7684\u65e0\u5e8f\u7ec4\u5408 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":5398,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[371,377],"tags":[],"_links":{"self":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/5397"}],"collection":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5397"}],"version-history":[{"count":0,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/5397\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/media\/5398"}],"wp:attachment":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5397"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5397"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}