{"id":7007,"date":"2025-02-05T07:35:12","date_gmt":"2025-02-05T07:35:12","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=7007"},"modified":"2025-02-05T07:35:51","modified_gmt":"2025-02-05T07:35:51","slug":"how-to-sort-python-dictionary-by-value","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/how-to-sort-python-dictionary-by-value\/","title":{"rendered":"How to Sort Python Dictionary By Value"},"content":{"rendered":"\n<p>Python dict is a versatile data structure that allows you to easily store diverse amount of data as key-value pairs, in a compact manner. They can be easily converted into JSON objects and vice versa. While working with Python dictionary, developers may need to sort the key-value pairs by key or value, or both. There are several ways to do this in Python. In this article, we will learn how to sort Python dictionary by value.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-sort-python-dictionary-by-value\/#How_to_Sort_Python_Dictionary_By_Value\" >How to Sort Python Dictionary By Value<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-sort-python-dictionary-by-value\/#1_Using_sort\" >1. Using sort()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-sort-python-dictionary-by-value\/#2_Using_sorted\" >2. Using sorted()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-sort-python-dictionary-by-value\/#3_Using_Numpy\" >3. Using Numpy<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-sort-python-dictionary-by-value\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Sort_Python_Dictionary_By_Value\"><\/span>How to Sort Python Dictionary By Value<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Before we proceed, it is important to note that for Python &lt;3.7, dictionary cannot be sorted, but they can only be sorted during display. Also, they are stored in random order. In Python >=3.7, the key-value pairs are stored in order of insertion.<\/p>\n\n\n\n<p>Let us say you have the following dict in Python.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">data = {'a':1, ,'c':2, 'b':3}<\/pre>\n\n\n\n<p>Here are the different ways to sort above dictionary by keys as well as value.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Using_sort\"><\/span>1. Using sort()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can use sort() function in Python to sort a list. We will use it to sort the list of keys of dict. The list of keys is obtained using keys() function readily available for each dict. Then we will use this sorted list to extract the corresponding values from original dictionary, and store each key-value pair in a new dictionary. At the end of it, the new dictionary will contain the sorted key-value pairs.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">keys = list(data.keys())<br>keys.sort()<br><br># sorted dict<br>sorted_data = {i: data[i] for i in keys}<br>print(sorted_data) # output is {'a': 1, 'b': 2, 'c': 3}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Using_sorted\"><\/span>2. Using sorted()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Python provides <a href=\"https:\/\/docs.python.org\/3\/howto\/sorting.html\">sorted()<\/a> function that returns a sorted list of an iterable object. It sorts string values alphabetically and numbers numerically. It also allows you to mention the sort key or specify a formula for it. Here is an example to sort a dict using its values.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">d1={k: v for k, v in sorted(data.items(), key=lambda item: item[1])}<br>print(d1)<\/pre>\n\n\n\n<p>In the above code, we call sorted() function on output of data.items(). data.items() returns a list of tuples where each tuple has a key-value pair. We also specify the key to be the 2nd item in each tuple, that is, the value, and not the key. For this, we use lambda function. The sorted() function returns a list of tuples, that have been sorted by the 2nd item in each tuple. <\/p>\n\n\n\n<p>We use a list comprehension to create key-value pairs out of each tuple and store each of them in a new dictionary.<\/p>\n\n\n\n<p>Here is the output.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{'a': 1, 'c': 2, 'b': 3}<\/pre>\n\n\n\n<p>Alternatively, you can call the dict() function to convert the result of sorted() function into dict.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">d1=dict(sorted(data.items(), key=lambda item: item[1]))<br>print(d1) # output is {'a': 1, 'c': 2, 'b': 3}<\/pre>\n\n\n\n<p>If you want to reverse sort the dictionary, then mention reverse=True argument in sorted function.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Using_Numpy\"><\/span>3. Using Numpy<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Numpy is a powerful Python library that allows you to easily work with numbers and data. It provides argsort() function that returns a list of indexes that will sort an array.<\/p>\n\n\n\n<p>Here is the code to demonstrate it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import numpy as np<br>data = {'a':1,'c':2,'b':3}<br>keys = list(data.keys())<br>values = list(data.values())<br>sorted_value_index = np.argsort(values)<br>sorted_dict = {keys[i]: values[i] for i in sorted_value_index}<br><br>print(sorted_dict)<\/pre>\n\n\n\n<p>In the above code, we create 2 lists &#8211; keys and values &#8211; containing all the keys and values of the dict respectively. Then we call argsort() function on the values list. It returns the list of indexes that will sort this array. We use the same list to extract key as well as corresponding value from keys and values lists, and create a new dict that is sorted.<\/p>\n\n\n\n<p>Here is the output.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{'a': 1, 'c': 2, 'b': 3}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this article, we have learnt several ways to sort a dictionary. Please note, in all the above cases, the original dictionary cannot be sorted. You can only create a new dictionary with the sorted order of items from the original dictionary. Of course, if you are using Python >=3.7, then the dict stores the items in the order of insertion. So if you want to save time and effort, it is better to store the items in the right order during the creation of dict itself.<\/p>\n\n\n\n<p>Also read:<\/p>\n\n\n\n<p><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-rename-columns-in-pandas\/\">How to Rename Columns in Pandas<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-select-rows-from-dataframe-based-on-column-values\/\">How to Select Rows from DataFrame Based on Column Values<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-concatenate-two-lists-in-python\/\">How to Concatenate Two Lists in Python<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes Python developers need to sort Python dictionary by value or key. Here are the different ways to do this.<\/p>\n","protected":false},"author":1,"featured_media":7027,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[301],"tags":[385],"class_list":["post-7007","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-sort-python-dict"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Sort Python Dictionary By Value - Ubiq BI<\/title>\n<meta name=\"description\" content=\"Sometimes Python developers need to sort Python dictionary by value or key. Here are the different ways to do this.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-sort-python-dictionary-by-value\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Sort Python Dictionary By Value - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"Sometimes Python developers need to sort Python dictionary by value or key. Here are the different ways to do this.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/how-to-sort-python-dictionary-by-value\/\" \/>\n<meta property=\"og:site_name\" content=\"Ubiq BI\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ubiqbi\" \/>\n<meta property=\"article:published_time\" content=\"2025-02-05T07:35:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-05T07:35:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/sort-dictionary-by-value.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"269\" \/>\n\t<meta property=\"og:image:height\" content=\"202\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sreeram Sreenivasan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:site\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sreeram Sreenivasan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-sort-python-dictionary-by-value\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-sort-python-dictionary-by-value\\\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to Sort Python Dictionary By Value\",\"datePublished\":\"2025-02-05T07:35:12+00:00\",\"dateModified\":\"2025-02-05T07:35:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-sort-python-dictionary-by-value\\\/\"},\"wordCount\":638,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-sort-python-dictionary-by-value\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/sort-dictionary-by-value.jpg?fit=269%2C202&ssl=1\",\"keywords\":[\"sort python dict\"],\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-sort-python-dictionary-by-value\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-sort-python-dictionary-by-value\\\/\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-sort-python-dictionary-by-value\\\/\",\"name\":\"How to Sort Python Dictionary By Value - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-sort-python-dictionary-by-value\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-sort-python-dictionary-by-value\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/sort-dictionary-by-value.jpg?fit=269%2C202&ssl=1\",\"datePublished\":\"2025-02-05T07:35:12+00:00\",\"dateModified\":\"2025-02-05T07:35:51+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"Sometimes Python developers need to sort Python dictionary by value or key. Here are the different ways to do this.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-sort-python-dictionary-by-value\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-sort-python-dictionary-by-value\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-sort-python-dictionary-by-value\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/sort-dictionary-by-value.jpg?fit=269%2C202&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/sort-dictionary-by-value.jpg?fit=269%2C202&ssl=1\",\"width\":269,\"height\":202,\"caption\":\"sort python dictionary by value\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-sort-python-dictionary-by-value\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Sort Python Dictionary By Value\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\",\"name\":\"Ubiq BI\",\"description\":\"Build dashboards &amp; reports in minutes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\",\"name\":\"Sreeram Sreenivasan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"caption\":\"Sreeram Sreenivasan\"},\"description\":\"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/sreeram-sreenivasan\\\/\"],\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/author\\\/wordpress\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Sort Python Dictionary By Value - Ubiq BI","description":"Sometimes Python developers need to sort Python dictionary by value or key. Here are the different ways to do this.","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:\/\/ubiq.co\/tech-blog\/how-to-sort-python-dictionary-by-value\/","og_locale":"en_US","og_type":"article","og_title":"How to Sort Python Dictionary By Value - Ubiq BI","og_description":"Sometimes Python developers need to sort Python dictionary by value or key. Here are the different ways to do this.","og_url":"https:\/\/ubiq.co\/tech-blog\/how-to-sort-python-dictionary-by-value\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2025-02-05T07:35:12+00:00","article_modified_time":"2025-02-05T07:35:51+00:00","og_image":[{"width":269,"height":202,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/sort-dictionary-by-value.jpg","type":"image\/jpeg"}],"author":"Sreeram Sreenivasan","twitter_card":"summary_large_image","twitter_creator":"@UbiqBI","twitter_site":"@UbiqBI","twitter_misc":{"Written by":"Sreeram Sreenivasan","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-sort-python-dictionary-by-value\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-sort-python-dictionary-by-value\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to Sort Python Dictionary By Value","datePublished":"2025-02-05T07:35:12+00:00","dateModified":"2025-02-05T07:35:51+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-sort-python-dictionary-by-value\/"},"wordCount":638,"commentCount":0,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-sort-python-dictionary-by-value\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/sort-dictionary-by-value.jpg?fit=269%2C202&ssl=1","keywords":["sort python dict"],"articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ubiq.co\/tech-blog\/how-to-sort-python-dictionary-by-value\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-sort-python-dictionary-by-value\/","url":"https:\/\/ubiq.co\/tech-blog\/how-to-sort-python-dictionary-by-value\/","name":"How to Sort Python Dictionary By Value - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-sort-python-dictionary-by-value\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-sort-python-dictionary-by-value\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/sort-dictionary-by-value.jpg?fit=269%2C202&ssl=1","datePublished":"2025-02-05T07:35:12+00:00","dateModified":"2025-02-05T07:35:51+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"Sometimes Python developers need to sort Python dictionary by value or key. Here are the different ways to do this.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-sort-python-dictionary-by-value\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/how-to-sort-python-dictionary-by-value\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-sort-python-dictionary-by-value\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/sort-dictionary-by-value.jpg?fit=269%2C202&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/sort-dictionary-by-value.jpg?fit=269%2C202&ssl=1","width":269,"height":202,"caption":"sort python dictionary by value"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-sort-python-dictionary-by-value\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How to Sort Python Dictionary By Value"}]},{"@type":"WebSite","@id":"https:\/\/ubiq.co\/tech-blog\/#website","url":"https:\/\/ubiq.co\/tech-blog\/","name":"Ubiq BI","description":"Build dashboards &amp; reports in minutes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc","name":"Sreeram Sreenivasan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","caption":"Sreeram Sreenivasan"},"description":"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.","sameAs":["https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/"],"url":"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/02\/sort-dictionary-by-value.jpg?fit=269%2C202&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-1P1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7007","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/comments?post=7007"}],"version-history":[{"count":20,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7007\/revisions"}],"predecessor-version":[{"id":7028,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7007\/revisions\/7028"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/7027"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=7007"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=7007"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=7007"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}