{"id":8405,"date":"2020-05-10T22:37:39","date_gmt":"2020-05-10T17:07:39","guid":{"rendered":"https:\/\/tutorials.eyehunts.com\/?p=8405"},"modified":"2021-08-04T18:54:44","modified_gmt":"2021-08-04T13:24:44","slug":"python-sort-tuple-order-example","status":"publish","type":"post","link":"https:\/\/tutorial.eyehunts.com\/python\/python-sort-tuple-order-example\/","title":{"rendered":"Python sort tuple | Order Example"},"content":{"rendered":"\n<p>You can sort the tuple by using the built-in function sorted()&nbsp;or <a href=\"https:\/\/tutorial.eyehunts.com\/\/python\/python-sort-list-of-strings-alphabetically-number\/\">sort()<\/a> in Python. <code>sorted()<\/code>&nbsp;returns the sorted sequence. If you want to sort a list in place then use&nbsp;<code>list.sort()<\/code>.<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Examples of sorting tuple in Python<\/strong><\/h2>\n\n\n\n<p>let&#8217;s see the example of using multiple methods to sort a <a href=\"https:\/\/tutorial.eyehunts.com\/\/python\/python-tuples-tuorial-example\/\" target=\"_blank\" rel=\"noreferrer noopener\">tuple in python<\/a>.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Use of&nbsp;sorted()&nbsp;method<\/strong><\/h3>\n\n\n\n<p>The sorted () function will sort a tuple and returns a tuple with the elements in a sorted manner, without modifying the original sequence ( Will create a new tuple). See below example of it:-<\/p>\n\n\n\n<pre>\ntup = [('lucky', '18.265'), ('nikhil', '14.107'), ('akash', '24.541'),\n       ('anand', '4.256'), ('gaurav', '10.365')]\nprint(sorted(tup))\n\n\n<\/pre>\n\n\n\n<p><strong>Output: <\/strong><\/p>\n\n\n\n<p>[(&#8216;akash&#8217;, &#8216;24.541&#8217;), (&#8216;anand&#8217;, &#8216;4.256&#8217;), (&#8216;gaurav&#8217;, &#8216;10.365&#8217;), (&#8216;lucky&#8217;, &#8216;18.265&#8217;), (&#8216;nikhil&#8217;, &#8216;14.107&#8217;)]<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>In-place way of sorting using sort():<\/strong><\/h3>\n\n\n\n<p>While sorting a tuple element order via sort() function the actual content of the tuple is changed, while in the sorted() function the content of the original tuple remained the same.<\/p>\n\n\n\n<pre>\ntup = [('lucky', '18.265'), ('nikhil', '14.107'), ('akash', '24.541'),\n       ('anand', '4.256'), ('gaurav', '10.365')]\n\n# Sorting a tuple\ntup.sort()\nprint(tup)\n<\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<p>[(&#8216;akash&#8217;, &#8216;24.541&#8217;), (&#8216;anand&#8217;, &#8216;4.256&#8217;), (&#8216;gaurav&#8217;, &#8216;10.365&#8217;), (&#8216;lucky&#8217;, &#8216;18.265&#8217;), (&#8216;nikhil&#8217;, &#8216;14.107&#8217;)]<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Q: How to Sort Tuples in Increasing Order by any key?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong>  You need to sort them according to any given key. So you have to use the sorted() function where we sort them using key=last and store last as the key index according to which we have to sort the given tuples.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Input: A = &#91;(2, 55), (1, 20), (4, 40), (2, 30)] \n            k = 0\nOutput: &#91;(1, 20), (2, 30), (2, 55), (4, 40)]<\/code><\/pre>\n\n\n\n<p>Example of Increasing Sorted order using the 0th index key.<\/p>\n\n\n\n<pre>def data(n):\nreturn n[k]\n\n\ndef tuplesort(tup):\nreturn sorted(tup, key=data)\n\n\n# Driver code\na = [(230, 456, 120), (205, 414, 39), (89, 410, 213)]\nk = int(input(\"Enter the Index ::>\"))\nprint(\"Sorted:\"),\nprint(tuplesort(a))<\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-medium\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"96\" src=\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/\/wp-content\/uploads\/2020\/05\/Python-sort-tuple-Order-Example-1-300x96.png?resize=300%2C96&#038;ssl=1\" alt=\"Python sort tuple Order Example\" class=\"wp-image-8442\" srcset=\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2020\/05\/Python-sort-tuple-Order-Example-1.png?resize=300%2C96&amp;ssl=1 300w, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2020\/05\/Python-sort-tuple-Order-Example-1.png?resize=768%2C246&amp;ssl=1 768w, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2020\/05\/Python-sort-tuple-Order-Example-1.png?w=892&amp;ssl=1 892w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/figure><\/div>\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 and suggestions on this tutorial.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Note:<\/strong><br>IDE:\u00a0<a rel=\"noreferrer noopener\" href=\"https:\/\/www.jetbrains.com\/pycharm\/\" target=\"_blank\">PyCharm<\/a>\u00a02020.1.1 (Community Edition)<br>macOS 10.15.4<br><strong>Python 3.7<\/strong><br>All<strong>\u00a0Python Examples\u00a0are in\u00a0Python\u00a03<\/strong>, so Maybe its different from python 2 or upgraded versions.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>You can sort the tuple by using the built-in function sorted()&nbsp;or sort() in Python. sorted()&nbsp;returns the sorted sequence. If you want to sort a list in place then use&nbsp;list.sort(). Examples of sorting tuple in Python let&#8217;s see the example of using multiple methods to sort a tuple in python. Use of&nbsp;sorted()&nbsp;method The sorted () function&hellip;&nbsp;<a href=\"https:\/\/tutorial.eyehunts.com\/python\/python-sort-tuple-order-example\/\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Python sort tuple | Order Example<\/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":[100],"post_series":[],"class_list":["post-8405","post","type-post","status-publish","format-standard","hentry","category-python","tag-python-tuple"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.1.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python sort tuple Example | How to set the Order - EyeHunts<\/title>\n<meta name=\"description\" content=\"Sort the tuple by using built-in function sorted() or sort() in Python. sorted() returns sorted sequence. And sort a list in place then use list.sort()\" \/>\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-tuple-order-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python sort tuple Example | How to set the Order - EyeHunts\" \/>\n<meta property=\"og:description\" content=\"Sort the tuple by using built-in function sorted() or sort() in Python. sorted() returns sorted sequence. And sort a list in place then use list.sort()\" \/>\n<meta property=\"og:url\" content=\"https:\/\/tutorial.eyehunts.com\/python\/python-sort-tuple-order-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:published_time\" content=\"2020-05-10T17:07:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-04T13:24:44+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/tutorial.eyehunts.com\/\/wp-content\/uploads\/2020\/05\/Python-sort-tuple-Order-Example-1-300x96.png\" \/>\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=\"2 minutes\" \/>\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-tuple-order-example\/\",\"url\":\"https:\/\/tutorial.eyehunts.com\/python\/python-sort-tuple-order-example\/\",\"name\":\"Python sort tuple Example | How to set the Order - EyeHunts\",\"isPartOf\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/python-sort-tuple-order-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/python-sort-tuple-order-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/tutorial.eyehunts.com\/\/wp-content\/uploads\/2020\/05\/Python-sort-tuple-Order-Example-1-300x96.png\",\"datePublished\":\"2020-05-10T17:07:39+00:00\",\"dateModified\":\"2021-08-04T13:24:44+00:00\",\"author\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1\"},\"description\":\"Sort the tuple by using built-in function sorted() or sort() in Python. sorted() returns sorted sequence. And sort a list in place then use list.sort()\",\"breadcrumb\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/python-sort-tuple-order-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/tutorial.eyehunts.com\/python\/python-sort-tuple-order-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/python-sort-tuple-order-example\/#primaryimage\",\"url\":\"https:\/\/tutorial.eyehunts.com\/\/wp-content\/uploads\/2020\/05\/Python-sort-tuple-Order-Example-1-300x96.png\",\"contentUrl\":\"https:\/\/tutorial.eyehunts.com\/\/wp-content\/uploads\/2020\/05\/Python-sort-tuple-Order-Example-1-300x96.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/python-sort-tuple-order-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/tutorial.eyehunts.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python sort tuple | Order Example\"}]},{\"@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 tuple Example | How to set the Order - EyeHunts","description":"Sort the tuple by using built-in function sorted() or sort() in Python. sorted() returns sorted sequence. And sort a list in place then use list.sort()","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-tuple-order-example\/","og_locale":"en_US","og_type":"article","og_title":"Python sort tuple Example | How to set the Order - EyeHunts","og_description":"Sort the tuple by using built-in function sorted() or sort() in Python. sorted() returns sorted sequence. And sort a list in place then use list.sort()","og_url":"https:\/\/tutorial.eyehunts.com\/python\/python-sort-tuple-order-example\/","og_site_name":"Tutorial","article_published_time":"2020-05-10T17:07:39+00:00","article_modified_time":"2021-08-04T13:24:44+00:00","og_image":[{"url":"https:\/\/tutorial.eyehunts.com\/\/wp-content\/uploads\/2020\/05\/Python-sort-tuple-Order-Example-1-300x96.png","type":"","width":"","height":""}],"author":"Rohit","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Rohit","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/tutorial.eyehunts.com\/python\/python-sort-tuple-order-example\/","url":"https:\/\/tutorial.eyehunts.com\/python\/python-sort-tuple-order-example\/","name":"Python sort tuple Example | How to set the Order - EyeHunts","isPartOf":{"@id":"https:\/\/tutorial.eyehunts.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/python-sort-tuple-order-example\/#primaryimage"},"image":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/python-sort-tuple-order-example\/#primaryimage"},"thumbnailUrl":"https:\/\/tutorial.eyehunts.com\/\/wp-content\/uploads\/2020\/05\/Python-sort-tuple-Order-Example-1-300x96.png","datePublished":"2020-05-10T17:07:39+00:00","dateModified":"2021-08-04T13:24:44+00:00","author":{"@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1"},"description":"Sort the tuple by using built-in function sorted() or sort() in Python. sorted() returns sorted sequence. And sort a list in place then use list.sort()","breadcrumb":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/python-sort-tuple-order-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/tutorial.eyehunts.com\/python\/python-sort-tuple-order-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorial.eyehunts.com\/python\/python-sort-tuple-order-example\/#primaryimage","url":"https:\/\/tutorial.eyehunts.com\/\/wp-content\/uploads\/2020\/05\/Python-sort-tuple-Order-Example-1-300x96.png","contentUrl":"https:\/\/tutorial.eyehunts.com\/\/wp-content\/uploads\/2020\/05\/Python-sort-tuple-Order-Example-1-300x96.png"},{"@type":"BreadcrumbList","@id":"https:\/\/tutorial.eyehunts.com\/python\/python-sort-tuple-order-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/tutorial.eyehunts.com\/"},{"@type":"ListItem","position":2,"name":"Python sort tuple | Order Example"}]},{"@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":8435,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-sorted-function-sort-string-list-tuple-dictionary\/","url_meta":{"origin":8405,"position":0},"title":"Python sorted function | Sort string, list, tuple, dictionary","author":"Rohit","date":"May 11, 2020","format":false,"excerpt":"Python sorted() function is used to sort string, list, tuple, dictionary, etc and it returns a list with the elements in a sorted manner, without modifying the original sequence. Syntax sorted(iterable, key=key, reverse=reverse) Parameter Values The sorted() method takes an of three parameters: iterable\u00a0- A sequence or collection or any\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python sorted function Sort the list of Number String","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Python-sorted-function-Sort-the-list-of-Number-String-.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":18047,"url":"https:\/\/tutorial.eyehunts.com\/python\/sort-list-of-tuples-by-first-element-python-example-code\/","url_meta":{"origin":8405,"position":1},"title":"Sort list of tuples by first element Python | Example code","author":"Rohit","date":"November 12, 2021","format":false,"excerpt":"Using the sorted() function or in-place sort are the ways to Sort a list of tuples by the first element in Python. Both methods need to use the key keyword. Note: key should be a function that identifies how to retrieve the comparable element from your data structure. In your\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Sort list of tuples by first element Python","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/11\/Sort-list-of-tuples-by-first-element-Python.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2027,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-tuples-tuorial-example\/","url_meta":{"origin":8405,"position":2},"title":"Python Tuples &#8211; Tutorial | Functions | Examples","author":"Rohit","date":"August 16, 2018","format":false,"excerpt":"Python\u00a0Tuples:\u00a0are very similar to Lists, the\u00a0only difference is that tuples are not mutable, so you cannot change a tuple. Lists are used much more than tuples\u00a0so tuples are only using very specific scenarios. A\u00a0tuple\u00a0is a sequence of immutable\u00a0Python\u00a0objects (data structure).\u00a0A tuple consists of a number of values separated by commas.\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python Tuples - Tutorial Functions Examples","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2018\/08\/Python-Tuples-Tutorial-Functions-Examples.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2018\/08\/Python-Tuples-Tutorial-Functions-Examples.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2018\/08\/Python-Tuples-Tutorial-Functions-Examples.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2018\/08\/Python-Tuples-Tutorial-Functions-Examples.png?resize=700%2C400&ssl=1 2x"},"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":8405,"position":3},"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":20608,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-sort-set-example-code\/","url_meta":{"origin":8405,"position":4},"title":"Python sort set | Example code","author":"Rohit","date":"October 6, 2021","format":false,"excerpt":"Use the sort() or sorted() method to sort the set in Python. As you know sets are unordered and it's not possible to sort the values of a set but if we print a set, it is displayed in a sorted manner. s = {5, 2, 7, 1, 8} print(s)\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python sort set","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Python-sort-set.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":18267,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-remove-duplicates-from-list-of-lists-example-code\/","url_meta":{"origin":8405,"position":5},"title":"Python remove duplicates from list of lists | Example code","author":"Rohit","date":"August 20, 2021","format":false,"excerpt":"Use the itertools to remove duplicates from a list of lists in Python. The itertools often offers the fastest and most powerful solutions to this kind of problem. Example remove duplicates from the lists of list in Python Simple example code. Before removing duplicates from a list you have to\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python remove duplicates from list of lists","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Python-remove-duplicates-from-list-of-lists.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\/8405","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=8405"}],"version-history":[{"count":1,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/8405\/revisions"}],"predecessor-version":[{"id":17566,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/8405\/revisions\/17566"}],"wp:attachment":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/media?parent=8405"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/categories?post=8405"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/tags?post=8405"},{"taxonomy":"post_series","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/post_series?post=8405"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}