{"id":512,"date":"2020-10-05T21:45:44","date_gmt":"2020-10-05T21:45:44","guid":{"rendered":"http:\/\/feellikelearning.com\/?p=512"},"modified":"2022-12-06T06:49:55","modified_gmt":"2022-12-06T06:49:55","slug":"cn-how-to-sort-by-value-in-python-dict","status":"publish","type":"post","link":"https:\/\/feellikelearning.com\/index.php\/2020\/10\/05\/cn-how-to-sort-by-value-in-python-dict\/","title":{"rendered":"Python\u91cc\u600e\u4e48\u6309dict value\u6765\u6392\u5e8f\uff1f \uff5c how to sort by value in python dict"},"content":{"rendered":"\n<p>\u7b80\u5355\u6765\u8bf4\u5c31\u662f\u5148\u751f\u6210 value =&gt; key \u7684tuples\uff0c\u7136\u540ecall sorted<\/p>\n\n\n\n<!--more-->\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sorted(\n    [(my_map.get(k), k) for k in my_map],\n    reverse=True\n)<\/pre>\n\n\n\n<p>\u53e6\u4e00\u79cd\u65b9\u6cd5\u662fcall dict\u7684items\u6765\u4ea7\u751fdict_items\uff0c\u8fd9\u4e2a\u5927\u6982\u5c31\u50cflist of tuples with key and value\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">d = {'a':1, 'b':2, 'c':3, 'd':64}\nd.items()<\/pre>\n\n\n\n<p>\u8f93\u51fa<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">dict_items([('a', 1), ('b', 2), ('c', 3), ('d', 64)])<\/pre>\n\n\n\n<p>\u6240\u4ee5\u6392\u5e8f\u53ef\u4ee5\u7528<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sorted([(v, k) for k,v in d.items()], reverse=True)<\/pre>\n\n\n\n<p>\u8f93\u51fa<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">[(64, 'd'), (3, 'c'), (2, 'b'), (1, 'a')]<\/pre>\n\n\n\n<p><a href=\"http:\/\/feellikelearning.com\/index.php\/2020\/10\/05\/cn-how-to-sort-by-value-in-python-dict\/\" target=\"_blank\" rel=\"noreferrer noopener\">\u672c\u6587\u94fe\u63a5<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7b80\u5355\u6765\u8bf4\u5c31\u662f\u5148\u751f\u6210 value =&gt; key \u7684tuples\uff0c\u7136\u540ecall sorted<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false},"categories":[1],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v19.10 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python\u91cc\u600e\u4e48\u6309dict value\u6765\u6392\u5e8f\uff1f \uff5c how to sort by value in python dict | Feel Like Learning<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/feellikelearning.com\/index.php\/2020\/10\/05\/cn-how-to-sort-by-value-in-python-dict\/?variant=zh-hant\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python\u91cc\u600e\u4e48\u6309dict value\u6765\u6392\u5e8f\uff1f \uff5c how to sort by value in python dict | Feel Like Learning\" \/>\n<meta property=\"og:description\" content=\"\u7b80\u5355\u6765\u8bf4\u5c31\u662f\u5148\u751f\u6210 value =&gt; key \u7684tuples\uff0c\u7136\u540ecall sorted\" \/>\n<meta property=\"og:url\" content=\"https:\/\/feellikelearning.com\/index.php\/2020\/10\/05\/cn-how-to-sort-by-value-in-python-dict\/?variant=zh-hant\" \/>\n<meta property=\"og:site_name\" content=\"Feel Like Learning\" \/>\n<meta property=\"article:published_time\" content=\"2020-10-05T21:45:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-12-06T06:49:55+00:00\" \/>\n<meta name=\"author\" content=\"feellikelearning\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"feellikelearning\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/10\/05\/cn-how-to-sort-by-value-in-python-dict\/?variant=zh-hant#article\",\"isPartOf\":{\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/10\/05\/cn-how-to-sort-by-value-in-python-dict\/?variant=zh-hant\"},\"author\":{\"name\":\"feellikelearning\",\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a\"},\"headline\":\"Python\u91cc\u600e\u4e48\u6309dict value\u6765\u6392\u5e8f\uff1f \uff5c how to sort by value in python dict\",\"datePublished\":\"2020-10-05T21:45:44+00:00\",\"dateModified\":\"2022-12-06T06:49:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/10\/05\/cn-how-to-sort-by-value-in-python-dict\/?variant=zh-hant\"},\"wordCount\":29,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/feellikelearning.com\/index.php\/2020\/10\/05\/cn-how-to-sort-by-value-in-python-dict\/?variant=zh-hant#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/10\/05\/cn-how-to-sort-by-value-in-python-dict\/?variant=zh-hant\",\"url\":\"https:\/\/feellikelearning.com\/index.php\/2020\/10\/05\/cn-how-to-sort-by-value-in-python-dict\/?variant=zh-hant\",\"name\":\"Python\u91cc\u600e\u4e48\u6309dict value\u6765\u6392\u5e8f\uff1f \uff5c how to sort by value in python dict | Feel Like Learning\",\"isPartOf\":{\"@id\":\"https:\/\/feellikelearning.com\/#website\"},\"datePublished\":\"2020-10-05T21:45:44+00:00\",\"dateModified\":\"2022-12-06T06:49:55+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/10\/05\/cn-how-to-sort-by-value-in-python-dict\/?variant=zh-hant#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/feellikelearning.com\/index.php\/2020\/10\/05\/cn-how-to-sort-by-value-in-python-dict\/?variant=zh-hant\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/10\/05\/cn-how-to-sort-by-value-in-python-dict\/?variant=zh-hant#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/feellikelearning.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\u91cc\u600e\u4e48\u6309dict value\u6765\u6392\u5e8f\uff1f \uff5c how to sort by value in python dict\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/feellikelearning.com\/#website\",\"url\":\"https:\/\/feellikelearning.com\/\",\"name\":\"Feel Like Learning\",\"description\":\"\u7a0b\u5e8f\uff5c\u751f\u6d3b\uff5c\u5b66\u5230\u5c31\u662f\u8d5a\u5230\",\"publisher\":{\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/feellikelearning.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a\",\"name\":\"feellikelearning\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/72a1e86e9dcb0332e88bd7d54fd36c28?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/72a1e86e9dcb0332e88bd7d54fd36c28?s=96&d=mm&r=g\",\"caption\":\"feellikelearning\"},\"logo\":{\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/feellikelearning.com\/index.php\/author\/feellikelearning\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python\u91cc\u600e\u4e48\u6309dict value\u6765\u6392\u5e8f\uff1f \uff5c how to sort by value in python dict | Feel Like Learning","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/feellikelearning.com\/index.php\/2020\/10\/05\/cn-how-to-sort-by-value-in-python-dict\/?variant=zh-hant","og_locale":"en_US","og_type":"article","og_title":"Python\u91cc\u600e\u4e48\u6309dict value\u6765\u6392\u5e8f\uff1f \uff5c how to sort by value in python dict | Feel Like Learning","og_description":"\u7b80\u5355\u6765\u8bf4\u5c31\u662f\u5148\u751f\u6210 value =&gt; key \u7684tuples\uff0c\u7136\u540ecall sorted","og_url":"https:\/\/feellikelearning.com\/index.php\/2020\/10\/05\/cn-how-to-sort-by-value-in-python-dict\/?variant=zh-hant","og_site_name":"Feel Like Learning","article_published_time":"2020-10-05T21:45:44+00:00","article_modified_time":"2022-12-06T06:49:55+00:00","author":"feellikelearning","twitter_card":"summary_large_image","twitter_misc":{"Written by":"feellikelearning","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/feellikelearning.com\/index.php\/2020\/10\/05\/cn-how-to-sort-by-value-in-python-dict\/?variant=zh-hant#article","isPartOf":{"@id":"https:\/\/feellikelearning.com\/index.php\/2020\/10\/05\/cn-how-to-sort-by-value-in-python-dict\/?variant=zh-hant"},"author":{"name":"feellikelearning","@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a"},"headline":"Python\u91cc\u600e\u4e48\u6309dict value\u6765\u6392\u5e8f\uff1f \uff5c how to sort by value in python dict","datePublished":"2020-10-05T21:45:44+00:00","dateModified":"2022-12-06T06:49:55+00:00","mainEntityOfPage":{"@id":"https:\/\/feellikelearning.com\/index.php\/2020\/10\/05\/cn-how-to-sort-by-value-in-python-dict\/?variant=zh-hant"},"wordCount":29,"commentCount":0,"publisher":{"@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a"},"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/feellikelearning.com\/index.php\/2020\/10\/05\/cn-how-to-sort-by-value-in-python-dict\/?variant=zh-hant#respond"]}]},{"@type":"WebPage","@id":"https:\/\/feellikelearning.com\/index.php\/2020\/10\/05\/cn-how-to-sort-by-value-in-python-dict\/?variant=zh-hant","url":"https:\/\/feellikelearning.com\/index.php\/2020\/10\/05\/cn-how-to-sort-by-value-in-python-dict\/?variant=zh-hant","name":"Python\u91cc\u600e\u4e48\u6309dict value\u6765\u6392\u5e8f\uff1f \uff5c how to sort by value in python dict | Feel Like Learning","isPartOf":{"@id":"https:\/\/feellikelearning.com\/#website"},"datePublished":"2020-10-05T21:45:44+00:00","dateModified":"2022-12-06T06:49:55+00:00","breadcrumb":{"@id":"https:\/\/feellikelearning.com\/index.php\/2020\/10\/05\/cn-how-to-sort-by-value-in-python-dict\/?variant=zh-hant#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/feellikelearning.com\/index.php\/2020\/10\/05\/cn-how-to-sort-by-value-in-python-dict\/?variant=zh-hant"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/feellikelearning.com\/index.php\/2020\/10\/05\/cn-how-to-sort-by-value-in-python-dict\/?variant=zh-hant#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/feellikelearning.com\/"},{"@type":"ListItem","position":2,"name":"Python\u91cc\u600e\u4e48\u6309dict value\u6765\u6392\u5e8f\uff1f \uff5c how to sort by value in python dict"}]},{"@type":"WebSite","@id":"https:\/\/feellikelearning.com\/#website","url":"https:\/\/feellikelearning.com\/","name":"Feel Like Learning","description":"\u7a0b\u5e8f\uff5c\u751f\u6d3b\uff5c\u5b66\u5230\u5c31\u662f\u8d5a\u5230","publisher":{"@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/feellikelearning.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a","name":"feellikelearning","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/72a1e86e9dcb0332e88bd7d54fd36c28?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/72a1e86e9dcb0332e88bd7d54fd36c28?s=96&d=mm&r=g","caption":"feellikelearning"},"logo":{"@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/image\/"},"url":"https:\/\/feellikelearning.com\/index.php\/author\/feellikelearning\/"}]}},"_links":{"self":[{"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/posts\/512"}],"collection":[{"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/comments?post=512"}],"version-history":[{"count":7,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/posts\/512\/revisions"}],"predecessor-version":[{"id":1791,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/posts\/512\/revisions\/1791"}],"wp:attachment":[{"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/media?parent=512"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/categories?post=512"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/tags?post=512"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}