{"id":190,"date":"2023-02-22T22:03:46","date_gmt":"2023-02-22T14:03:46","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=190"},"modified":"2023-02-22T22:06:28","modified_gmt":"2023-02-22T14:06:28","slug":"python-traverse-dict-methods","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/22\/python-traverse-dict-methods\/","title":{"rendered":"Python\u904d\u5386\u5b57\u5178dict\u7684\u51e0\u79cd\u65b9\u6cd5"},"content":{"rendered":"<p>Python\u904d\u5386\u5b57\u5178dict\u7684\u51e0\u79cd\u65b9\u6cd5\uff1a<\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-python\"># -*- coding: utf-8 -*-\n\ndict = {&quot;apple&quot;: &quot;\u82f9\u679c&quot;, &quot;banana&quot;: &quot;\u9999\u8549&quot;, &quot;orange&quot;: &quot;\u6854\u5b50&quot;}\n\nprint &quot;----------dict----------&quot;\nfor k in dict:\n    print &quot;dict[%s] =&quot; % k, dict[k]\n\nprint &quot;----------items----------&quot;\nfor (k, v) in dict.items():\n    print &quot;dict[%s] =&quot; % k, v\n\nprint &quot;----------iteritems----------&quot;\nfor k, v in dict.iteritems():\n    print &quot;dict[%s]=&quot; % k, v\n\nprint &quot;----------iterkeys,itervalues----------&quot;\nfor k, v in zip(dict.iterkeys(), dict.itervalues()):\n    print &quot;dict[%s]=&quot; % k, v\n\nprint &quot;----------keys----------&quot;\nfor k in dict.keys():\n    print &quot;dict[%s]=&quot; % k, dict[k]\n\nprint &quot;----------keys values----------&quot;\nkeys = dict.keys()\nvalues = dict.values()\nfor i in range(len(dict)):\n    print &quot;dict[%s]=&quot; % keys[i], values[i]<\/code><\/pre>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<pre><code>----------dict----------\ndict[orange] = \u6854\u5b50\ndict[apple] = \u82f9\u679c\ndict[banana] = \u9999\u8549\n----------items----------\ndict[orange] = \u6854\u5b50\ndict[apple] = \u82f9\u679c\ndict[banana] = \u9999\u8549\n----------iteritems----------\ndict[orange]= \u6854\u5b50\ndict[apple]= \u82f9\u679c\ndict[banana]= \u9999\u8549\n----------iterkeys,itervalues----------\ndict[orange]= \u6854\u5b50\ndict[apple]= \u82f9\u679c\ndict[banana]= \u9999\u8549\n----------keys----------\ndict[orange]= \u6854\u5b50\ndict[apple]= \u82f9\u679c\ndict[banana]= \u9999\u8549\n----------keys values----------\ndict[orange]= \u6854\u5b50\ndict[apple]= \u82f9\u679c\ndict[banana]= \u9999\u8549<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Python\u904d\u5386\u5b57\u5178dict\u7684\u51e0\u79cd\u65b9\u6cd5\uff1a # -*- coding: utf-8 -*- dict = {&#038;q [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[79],"tags":[],"class_list":["post-190","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/190","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=190"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/190\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}