{"id":12750,"date":"2020-04-13T09:59:10","date_gmt":"2020-04-13T16:59:10","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=12750"},"modified":"2023-12-01T02:37:03","modified_gmt":"2023-12-01T10:37:03","slug":"sort-a-dictionary-by-value-in-python-2","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/","title":{"rendered":"Sort a Dictionary by Value in Python"},"content":{"rendered":"\n<p>Dictionaries are unordered data structures. They use a mapping structure to store data. Dictionaries map keys to values, creating pairs that hold related data.<\/p>\n\n\n\n<p>Using the Python <code>sorted()<\/code> method, you can sort the contents of a dictionary by value. For instance, to rank the popularity of items on a coffee menu, you can use Python\u2019s <code>sorted()<\/code> method. This tutorial will discuss how the <code>sorted()<\/code> method works and how you can use it to sort the contents of a dictionary.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Python sorted() Refresher<\/h2>\n\n\n\n<p>Python\u2019s built-in <code>sorted()<\/code> function can be used to sort iterable objects, such as lists, tuples, and dictionaries. The sorted() function sorts the items of the specified iterable object and creates a new object with the newly sorted values.<\/p>\n\n\n\n<p>Here\u2019s the syntax for the <code>sorted()<\/code> method:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>sorted(object, key, reverse)<\/pre><\/div>\n\n\n\n<p>The method takes in three parameters:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>object<\/strong>: the iterable object that you want to sort (required)<\/li>\n\n\n\n<li><strong>key<\/strong>: the function that allows you to perform custom sort operations (optional)<\/li>\n\n\n\n<li><strong>reverse<\/strong>: specifies whether the object should be sorted in descending order (optional)<\/li>\n<\/ul>\n\n\n\n<p>As you can see, <code>object<\/code> is the only required parameter. If you decide not to use the optional <code>key<\/code> and <code>reverse<\/code> parameters, Python will automatically sort the object in ascending order.<\/p>\n\n\n\n<p>Note: Career Karma wrote a full guide on the <code>sort()<\/code> and <code>sorted()<\/code> methods in Python. If you\u2019re looking to learn more about this method and the <code>key<\/code> parameter, check out our <a href=\"https:\/\/careerkarma.com\/blog\/python-sort\">Python sort() tutorial<\/a>.<\/p>\n\n\n\n<p>Let\u2019s walk through a quick example to illustrate how the <code>sorted()<\/code> method works.&nbsp;<\/p>\n\n\n\n<p>Say that we are operating a coffee shop and we want to retrieve an alphabetical list of our <code>Coffee Club<\/code> (loyalty) customers. We already have a list of customers, but it is ordered by sign-up date. We could use the following code to sort our list:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>customers = ['Kaley Fernandez', 'Darius Rowland', 'Isaac Borthwick',  'Alexandria Kidd']\nsorted_customers = sorted(customers)\nprint(sorted_customers)<\/pre><\/div>\n\n\n\n<p>Our code sorts the <code>customers<\/code> array and returns the following: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>['Alexandria Kidd', 'Darius Rowland', 'Isaac Borthwick', 'Kaley Fernandez']<\/pre><\/div>\n\n\n\n<p>On the first line of our code, we declare a list that stores our customers\u2019 names; this list is called: customers. Then, we use the <code>sorted()<\/code> method to sort the list of customer names in ascending order; this new list is called: <code>sorted_customers<\/code>. Finally, we print out the newly sorted list to the console using the <code>print()<\/code> function. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Sort a Dictionary by Value<\/h2>\n\n\n\n<p>Let\u2019s say that you have a dictionary and you want to sort it by key-value pairs. You can do this by using two functions together: <code>items()<\/code> and <code>sorted()<\/code>.&nbsp;<\/p>\n\n\n\n<p>The <code>items()<\/code> function allows you to retrieve the items in a dictionary. We can use this function in combination with the <code>sorted()<\/code> function and a custom <code>key<\/code> parameter to sort a dictionary by value. Consider the following two examples.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example 1: Sort in Descending Order<\/h3>\n\n\n\n<p>Let\u2019s return to the coffee shop. Suppose we have a dictionary that stores the items on our coffee menu as well as how many of each item were ordered in the last month. We want to see what the most popular coffee was last month, so we decide to sort the order dictionary in descending order of values.<\/p>\n\n\n\n<p>Here\u2019s a program we could use to sort the contents of our dictionary by value:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>orders = {\n\t'cappuccino': 54,\n\t'latte': 56,\n\t'espresso': 72,\n\t'americano': 48,\n\t'cortado': 41\n}\nsort_orders = sorted(orders.items(), key=lambda x: x[1], reverse=True)\nfor i in sort_orders:\n\tprint(i[0], i[1])<\/pre><\/div>\n\n\n\n<p>Our code returns the following: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>espresso 72\nlatte 56\ncappuccino 54\namericano 48\ncortado 41<\/pre><\/div>\n\n\n\n<p>There\u2019s a lot going on in our code, so let\u2019s break it down.&nbsp;<\/p>\n\n\n\n<p>At the start of our code, we define a dictionary called <code>orders<\/code> that stores the names of coffees as <strong>keys<\/strong> and the number sold as <strong>values<\/strong>.<\/p>\n\n\n\n<p>Then, we use the <code>sorted()<\/code> method to sort the <code>orders<\/code> dictionary by value. Here\u2019s a breakdown of how we used the <code>sorted()<\/code> method:<\/p>\n\n\n\n<figure class=\"wp-block-table course-info-table\"><table><tbody><tr><td><strong>Parameter<\/strong><\/td><td><strong>Text<\/strong><\/td><td><strong>Description<\/strong><\/td><\/tr><tr><td><strong>object<\/strong><\/td><td>orders.items()&nbsp;<\/td><td>Refers to all values in our \u201corders\u201d dictionary. If we were to use just \u201corders\u201d, we would have to reference the index position of the item to get its individual value. Whereas if we use orders.items(), an iterable list with the items in a list is created.<\/td><\/tr><tr><td><strong>key<\/strong><\/td><td>key=lambda x: x[1]<\/td><td>A <em>sorting mechanism<\/em> that allows us to sort our dictionary by value. This is an example of a Lambda function, which is a function without a name.<\/td><\/tr><tr><td><strong>reverse<\/strong><\/td><td>reverse=True<\/td><td>States that we want our data to be sorted in <em>descending order.<\/em><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Finally, we create a <code>for<\/code> loop that loops through each item created in our <code>sort_order<\/code> method and prints out both its key name and its value, sorted in the order we specified in the <code>sort_order<\/code> function.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example 2: Sort in Ascending Order<\/h3>\n\n\n\n<p>Similarly, if we wanted to find out the least popular drink sold at our coffee shop, we could use the same code as above but without the <code>reverse=True<\/code> parameter. Here\u2019s an example of the code for this:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>orders = {\n\t'cappuccino': 54,\n\t'latte': 56,\n\t'espresso': 72,\n\t'americano': 48,\n\t'cortado': 41\n}\nsort_orders = sorted(orders.items(), key=lambda x: x[1])\nfor i in sort_orders:\n\tprint(i[0], i[1])<\/pre><\/div>\n\n\n\n<p>When we run our code, the following values are returned: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>cortado 41\namericano 48\ncappuccino 54\nlatte 56\nespresso 72<\/pre><\/div>\n\n\n\n<p>As you can see, our code returned a list of items arranged in ascending order, based on the number of each item ordered in the last month.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">List Comprehension<\/h2>\n\n\n\n<p>In addition, we can use list comprehension to sort dictionary contents by value. List comprehension is a concise technique to create lists in Python and can save space if you are creating more complex sort methods.<\/p>\n\n\n\n<p>Here\u2019s the code we would use to sort our coffee orders in ascending order by the number of each coffee that was ordered using list comprehension:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>orders = {\n\t'cappuccino': 54,\n\t'latte': 56,\n\t'espresso': 72,\n\t'americano': 48,\n\t'cortado': 41\n}\n[print(key, value) for (key, value) in sorted(orders.items(), key=lambda x: x[1])]<\/pre><\/div>\n\n\n\n<p>When we run our code, the following response is returned: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>cortado 41\namericano 48\ncappuccino 54\nlatte 56\nespresso 72<\/pre><\/div>\n\n\n\n<p>The result of our code was the same as our above example where we sorted the contents of the <code>orders<\/code> list in ascending order. But instead of defining a <code>sort_orders<\/code> variable and creating a separate <code>for<\/code> loop to iterate through the sorted list, we created a list using the list comprehension technique.<\/p>\n\n\n\n<p>The list comprehension we created above sorts through each item in our list in ascending order, then prints out the key and value of each dictionary item to the console.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>When you\u2019re working with dictionaries in Python, sorting a dictionary by value is a common operation. The <code>sorted()<\/code> method allows you to sort a set of data based on your needs.<\/p>\n\n\n\n<p>This tutorial discussed, providing examples, how to use the <code>sorted()<\/code> method to sort a dictionary by value in Python, including how to use the <code>key<\/code> and <code>reverse<\/code> parameters.&nbsp;<\/p>\n\n\n\n<p>Now you\u2019re ready to start sorting dictionaries by value like a Python pro!<\/p>\n","protected":false},"excerpt":{"rendered":"Dictionaries are unordered data structures. They use a mapping structure to store data. Dictionaries map keys to values, creating pairs that hold related data. Using the Python sorted() method, you can sort the contents of a dictionary by value. For instance, to rank the popularity of items on a coffee menu, you can use Python\u2019s&hellip;","protected":false},"author":240,"featured_media":12751,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[16578],"tags":[],"class_list":{"0":"post-12750","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-python"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"Python","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":"","is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.0 (Yoast SEO v27.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Sort a Dictionary by Value in Python: A Complete Guide | Career Karma<\/title>\n<meta name=\"description\" content=\"Learn how to use the sorted() method to sort the contents of a dictionary by value in your Python code on Career Karma.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Sort a Dictionary by Value in Python\" \/>\n<meta property=\"og:description\" content=\"Learn how to use the sorted() method to sort the contents of a dictionary by value in your Python code on Career Karma.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-04-13T16:59:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T10:37:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/VALUE-IN-PYTHON.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"667\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"Sort a Dictionary by Value in Python\",\"datePublished\":\"2020-04-13T16:59:10+00:00\",\"dateModified\":\"2023-12-01T10:37:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/\"},\"wordCount\":1010,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/VALUE-IN-PYTHON.jpg\",\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/\",\"name\":\"Sort a Dictionary by Value in Python: A Complete Guide | Career Karma\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/VALUE-IN-PYTHON.jpg\",\"datePublished\":\"2020-04-13T16:59:10+00:00\",\"dateModified\":\"2023-12-01T10:37:03+00:00\",\"author\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"Learn how to use the sorted() method to sort the contents of a dictionary by value in your Python code on Career Karma.\",\"breadcrumb\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/#primaryimage\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/VALUE-IN-PYTHON.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/VALUE-IN-PYTHON.jpg\",\"width\":1000,\"height\":667},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\/\/careerkarma.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\",\"item\":\"https:\/\/careerkarma.com\/blog\/python\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Sort a Dictionary by Value in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\",\"url\":\"https:\/\/careerkarma.com\/blog\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/careerkarma.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Sort a Dictionary by Value in Python: A Complete Guide | Career Karma","description":"Learn how to use the sorted() method to sort the contents of a dictionary by value in your Python code on Career Karma.","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:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/","og_locale":"en_US","og_type":"article","og_title":"Sort a Dictionary by Value in Python","og_description":"Learn how to use the sorted() method to sort the contents of a dictionary by value in your Python code on Career Karma.","og_url":"https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-04-13T16:59:10+00:00","article_modified_time":"2023-12-01T10:37:03+00:00","og_image":[{"width":1000,"height":667,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/VALUE-IN-PYTHON.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"Sort a Dictionary by Value in Python","datePublished":"2020-04-13T16:59:10+00:00","dateModified":"2023-12-01T10:37:03+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/"},"wordCount":1010,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/VALUE-IN-PYTHON.jpg","articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/","url":"https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/","name":"Sort a Dictionary by Value in Python: A Complete Guide | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/VALUE-IN-PYTHON.jpg","datePublished":"2020-04-13T16:59:10+00:00","dateModified":"2023-12-01T10:37:03+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"Learn how to use the sorted() method to sort the contents of a dictionary by value in your Python code on Career Karma.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/VALUE-IN-PYTHON.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/VALUE-IN-PYTHON.jpg","width":1000,"height":667},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/sort-a-dictionary-by-value-in-python-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Python","item":"https:\/\/careerkarma.com\/blog\/python\/"},{"@type":"ListItem","position":3,"name":"Sort a Dictionary by Value in Python"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/12750","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=12750"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/12750\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/12751"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=12750"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=12750"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=12750"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}