{"id":19673,"date":"2021-09-14T16:46:22","date_gmt":"2021-09-14T11:16:22","guid":{"rendered":"https:\/\/tutorial.eyehunts.com\/?p=19673"},"modified":"2022-05-31T18:04:37","modified_gmt":"2022-05-31T12:34:37","slug":"python-sort-lambda-example-code","status":"publish","type":"post","link":"https:\/\/tutorial.eyehunts.com\/python\/python-sort-lambda-example-code\/","title":{"rendered":"Python sort lambda | Example code"},"content":{"rendered":"\n<p>Use the list <a href=\"https:\/\/tutorial.eyehunts.com\/python\/python-sort-list-array-function-strings-number-list\/\">sort() method<\/a> to sort a list with a lambda expression in Python. Just call the list.sort(key=None) with a key set to a lambda expression to sort the elements of the list by the key.<\/p>\n\n\n\n<p>Both <a href=\"https:\/\/docs.python.org\/3\/library\/stdtypes.html#list.sort\">list.sort()<\/a> and <a href=\"https:\/\/docs.python.org\/3\/library\/functions.html#sorted\">sorted()<\/a> have a key parameter to specify a function to be called on each list element prior to making comparisons.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Example sort lambda in Python<\/strong><\/h2>\n\n\n\n<p>Simple example code, sorting the data by index value 0.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>data = &#91;(\"B\", 5, \"20\"), (\"A\", 1, \"5\"), (\"C\", 6, \"10\")]\ndata.sort(key=lambda x: x&#91;0])\n\nprint(data)\n<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong>: <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"583\" height=\"143\" src=\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/09\/Python-sort-lambda.jpg?resize=583%2C143&#038;ssl=1\" alt=\"Python sort lambda\" class=\"wp-image-19766\"\/><\/figure><\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>Another example with the sorted() method<\/strong><\/p>\n\n\n\n<p>Here is code to sort through its &#8220;integers&#8221;.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ids = &#91;'id5', 'id1', 'id2', 'id5', 'id4', 'id3']\n\nres = sorted(ids, key=lambda x: int(x&#91;2:]))\n\nprint(res)<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong>: [&#8216;id1&#8217;, &#8216;id2&#8217;, &#8216;id3&#8217;, &#8216;id4&#8217;, &#8216;id5&#8217;, &#8216;id5&#8217;]<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>Revere sort the list using lambda<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ids = &#91;5, 2, 3, 1, 4]\n\nres = sorted(ids, key=lambda x: x, reverse=True)\n\nprint(res)\n<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong>: [5, 4, 3, 2, 1]<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Do comment if you have any doubts or suggestions on this Python lambda tutorial.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Note:<\/strong> IDE:&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/www.jetbrains.com\/pycharm\/\" target=\"_blank\">PyCharm<\/a>&nbsp;2021.3.3 (Community Edition)<\/p><p>Windows 10<\/p><p><strong>Python 3.10.1<\/strong><\/p><p>All<strong>&nbsp;Python Examples&nbsp;are in&nbsp;Python&nbsp;3<\/strong>, so Maybe its different from python 2 or upgraded versions.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Use the list sort() method to sort a list with a lambda expression in Python. Just call the list.sort(key=None) with a key set to a lambda expression to sort the elements of the list by the key. Both list.sort() and sorted() have a key parameter to specify a function to be called on each list&hellip;&nbsp;<a href=\"https:\/\/tutorial.eyehunts.com\/python\/python-sort-lambda-example-code\/\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Python sort lambda | Example code<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[30],"tags":[201,203],"post_series":[],"class_list":["post-19673","post","type-post","status-publish","format-standard","hentry","category-python","tag-python-lambda","tag-python-sort"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.1.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python sort lambda | Example code<\/title>\n<meta name=\"description\" content=\"Use the list sort() method to sorting a list with a lambda expression in Python. Just call list.sort(key=None) with key set to a lambda exp..\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/tutorial.eyehunts.com\/python\/python-sort-lambda-example-code\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python sort lambda | Example code\" \/>\n<meta property=\"og:description\" content=\"Use the list sort() method to sorting a list with a lambda expression in Python. Just call list.sort(key=None) with key set to a lambda exp..\" \/>\n<meta property=\"og:url\" content=\"https:\/\/tutorial.eyehunts.com\/python\/python-sort-lambda-example-code\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:published_time\" content=\"2021-09-14T11:16:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-05-31T12:34:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/09\/Python-sort-lambda.jpg\" \/>\n<meta name=\"author\" content=\"Rohit\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rohit\" \/>\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\":\"WebPage\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/python-sort-lambda-example-code\/\",\"url\":\"https:\/\/tutorial.eyehunts.com\/python\/python-sort-lambda-example-code\/\",\"name\":\"Python sort lambda | Example code\",\"isPartOf\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/python-sort-lambda-example-code\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/python-sort-lambda-example-code\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/09\/Python-sort-lambda.jpg\",\"datePublished\":\"2021-09-14T11:16:22+00:00\",\"dateModified\":\"2022-05-31T12:34:37+00:00\",\"author\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1\"},\"description\":\"Use the list sort() method to sorting a list with a lambda expression in Python. Just call list.sort(key=None) with key set to a lambda exp..\",\"breadcrumb\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/python-sort-lambda-example-code\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/tutorial.eyehunts.com\/python\/python-sort-lambda-example-code\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/python-sort-lambda-example-code\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/09\/Python-sort-lambda.jpg?fit=583%2C143&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/09\/Python-sort-lambda.jpg?fit=583%2C143&ssl=1\",\"width\":583,\"height\":143},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/python-sort-lambda-example-code\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/tutorial.eyehunts.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python sort lambda | Example code\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#website\",\"url\":\"https:\/\/tutorial.eyehunts.com\/\",\"name\":\"Tutorial\",\"description\":\"By EyeHunts\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/tutorial.eyehunts.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1\",\"name\":\"Rohit\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971\",\"contentUrl\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971\",\"caption\":\"Rohit\"},\"description\":\"Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology &amp; like learning technical.\",\"url\":\"https:\/\/tutorial.eyehunts.com\/author\/rohit\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python sort lambda | Example code","description":"Use the list sort() method to sorting a list with a lambda expression in Python. Just call list.sort(key=None) with key set to a lambda exp..","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:\/\/tutorial.eyehunts.com\/python\/python-sort-lambda-example-code\/","og_locale":"en_US","og_type":"article","og_title":"Python sort lambda | Example code","og_description":"Use the list sort() method to sorting a list with a lambda expression in Python. Just call list.sort(key=None) with key set to a lambda exp..","og_url":"https:\/\/tutorial.eyehunts.com\/python\/python-sort-lambda-example-code\/","og_site_name":"Tutorial","article_published_time":"2021-09-14T11:16:22+00:00","article_modified_time":"2022-05-31T12:34:37+00:00","og_image":[{"url":"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/09\/Python-sort-lambda.jpg","type":"","width":"","height":""}],"author":"Rohit","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Rohit","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/tutorial.eyehunts.com\/python\/python-sort-lambda-example-code\/","url":"https:\/\/tutorial.eyehunts.com\/python\/python-sort-lambda-example-code\/","name":"Python sort lambda | Example code","isPartOf":{"@id":"https:\/\/tutorial.eyehunts.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/python-sort-lambda-example-code\/#primaryimage"},"image":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/python-sort-lambda-example-code\/#primaryimage"},"thumbnailUrl":"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/09\/Python-sort-lambda.jpg","datePublished":"2021-09-14T11:16:22+00:00","dateModified":"2022-05-31T12:34:37+00:00","author":{"@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1"},"description":"Use the list sort() method to sorting a list with a lambda expression in Python. Just call list.sort(key=None) with key set to a lambda exp..","breadcrumb":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/python-sort-lambda-example-code\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/tutorial.eyehunts.com\/python\/python-sort-lambda-example-code\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorial.eyehunts.com\/python\/python-sort-lambda-example-code\/#primaryimage","url":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/09\/Python-sort-lambda.jpg?fit=583%2C143&ssl=1","contentUrl":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/09\/Python-sort-lambda.jpg?fit=583%2C143&ssl=1","width":583,"height":143},{"@type":"BreadcrumbList","@id":"https:\/\/tutorial.eyehunts.com\/python\/python-sort-lambda-example-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/tutorial.eyehunts.com\/"},{"@type":"ListItem","position":2,"name":"Python sort lambda | Example code"}]},{"@type":"WebSite","@id":"https:\/\/tutorial.eyehunts.com\/#website","url":"https:\/\/tutorial.eyehunts.com\/","name":"Tutorial","description":"By EyeHunts","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/tutorial.eyehunts.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1","name":"Rohit","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/image\/","url":"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971","contentUrl":"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971","caption":"Rohit"},"description":"Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology &amp; like learning technical.","url":"https:\/\/tutorial.eyehunts.com\/author\/rohit\/"}]}},"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":19770,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-list-sort-lambda-expression-example-code\/","url_meta":{"origin":19673,"position":0},"title":"Python list sort lambda expression | Example code","author":"Rohit","date":"December 16, 2021","format":false,"excerpt":"Use the list sort() method to sort with a lambda expression in Python. Both list.sort() and sorted() have a key parameter to specify a function to be called on each list element prior to making comparisons. Example of how to sort with lambda in Python Simple example code Call list\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python list sort lambda expression","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/12\/Python-list-sort-lambda-expression.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/12\/Python-list-sort-lambda-expression.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/12\/Python-list-sort-lambda-expression.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":8404,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-sort-list-of-tuples-descending-first-second-last-multiple-elements-value-alphabetically\/","url_meta":{"origin":19673,"position":1},"title":"Python sort list of tuples | descending, first, second, last, multiple elements, value, alphabetically","author":"Rohit","date":"May 19, 2020","format":false,"excerpt":"Python sort list of tuples using the sort method needed key which sorts lists in place. And also offers a convenient way to sort tuples based on the index of tuple elements. You can sort the list of tuples\u00a0by first and second elements by using indexes or values. tup[0]\u00a0to sort\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python sort list of tuples by multiple elements","src":"https:\/\/i1.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2020\/05\/Python-sort-list-of-tuples-by-multiple-elements-1.png?fit=1024%2C122&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i1.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2020\/05\/Python-sort-list-of-tuples-by-multiple-elements-1.png?fit=1024%2C122&ssl=1&resize=350%2C200 1x, https:\/\/i1.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2020\/05\/Python-sort-list-of-tuples-by-multiple-elements-1.png?fit=1024%2C122&ssl=1&resize=525%2C300 1.5x, https:\/\/i1.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2020\/05\/Python-sort-list-of-tuples-by-multiple-elements-1.png?fit=1024%2C122&ssl=1&resize=700%2C400 2x, https:\/\/i1.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2020\/05\/Python-sort-list-of-tuples-by-multiple-elements-1.png?fit=1024%2C122&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":35524,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-sorted-lambda\/","url_meta":{"origin":19673,"position":2},"title":"Python sorted lambda","author":"Rohit","date":"January 18, 2023","format":false,"excerpt":"Use sorted() function for simple data but complex objects using a lambda key function in Python. We can also add reverse=True, after the sorting condition, to sort the elements in reverse order. sorted(a, key=lambda x: x.modified, reverse=True) Take a look at this Example, you will understand: a = [\"tim\", \"bob\",\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2023\/01\/Python-sorted-lambda-example.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2023\/01\/Python-sorted-lambda-example.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2023\/01\/Python-sorted-lambda-example.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2023\/01\/Python-sorted-lambda-example.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2023\/01\/Python-sorted-lambda-example.jpg?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":19776,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-sort-list-of-dictionaries-example-code\/","url_meta":{"origin":19673,"position":3},"title":"Python sort list of dictionaries | Example code","author":"Rohit","date":"September 15, 2021","format":false,"excerpt":"Use lambda function with sorted() inbuilt function to sort the list of dictionaries in Python. Pass the list containing dictionaries and keys to the sorted method. Example sort list of dictionaries in Python A simple example code demonstrates the working of sorted() with lambda. We sort the list of dict\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/09\/Python-sort-list-of-dictionaries.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/09\/Python-sort-list-of-dictionaries.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/09\/Python-sort-list-of-dictionaries.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/09\/Python-sort-list-of-dictionaries.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/09\/Python-sort-list-of-dictionaries.jpg?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":19690,"url":"https:\/\/tutorial.eyehunts.com\/python\/key-lambda-python-keylambda-function-example\/","url_meta":{"origin":19673,"position":4},"title":"key lambda Python (Key=lambda) function example","author":"Rohit","date":"September 14, 2021","format":false,"excerpt":"Use key when you want to sort the data using the Python lambda function. The key lambda sorted could treat string items as an int to achieve this. This is why the key keyword argument is used. Note: A lambda is an anonymous function: Example Key=lambda Python Simple example code.\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"key lambda Python","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/09\/key-lambda-Python.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":8386,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-sort-list-array-function-strings-number-list\/","url_meta":{"origin":19673,"position":5},"title":"Python sort list (Array) | sorted function &#8211; Strings (alphabetically), Number, list","author":"Rohit","date":"May 7, 2020","format":false,"excerpt":"The python sort() function is used to sorts the elements of a given list. It sorts the list ascending, descending, or user-defined order where ascending order is by default. Note: Ascending order is by default in sort() method.It changes the original list and doesn't return any value. Syntax list.sort(reverse=True|False, key=myFunc)\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python sort list Array","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/07\/Python-sort-list-Array.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/19673","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/comments?post=19673"}],"version-history":[{"count":1,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/19673\/revisions"}],"predecessor-version":[{"id":30045,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/19673\/revisions\/30045"}],"wp:attachment":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/media?parent=19673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/categories?post=19673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/tags?post=19673"},{"taxonomy":"post_series","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/post_series?post=19673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}