{"id":6397,"date":"2020-12-16T13:14:37","date_gmt":"2020-12-16T07:44:37","guid":{"rendered":"http:\/\/www.pythonpool.com\/?p=6397"},"modified":"2021-06-14T16:00:32","modified_gmt":"2021-06-14T10:30:32","slug":"python-pigeonhole-sort","status":"publish","type":"post","link":"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/","title":{"rendered":"Pigeonhole Sort in Python With Algorithm and Code Snippet"},"content":{"rendered":"\n<p>In this article, we will dig into a sorting algorithm known as the <strong>pigeonhole sort<\/strong> in Python. So, what exactly is a pigeonhole sort? <strong>It is a sorting algorithm famously used for sorting the lists in which the number of elements in the list is approximately equal to the range of possible key values<\/strong>. Let us now understand the pigeonhole sort in detail.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_74 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">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: #990303;color:#990303\" 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: #990303;color:#990303\" 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 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/#Algorithm_for_Pigeonhole_Sort_in_Python\" >Algorithm for Pigeonhole Sort in Python:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/#Illustration_of_the_Algorithm\" >Illustration of the Algorithm:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/#Implementation_of_Pigeonhole_Sort_Algorithm_in_Python\" >Implementation of Pigeonhole Sort Algorithm in Python:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/#Analysis_of_the_Pigeonhole_Sort_Algorithm_in_Python\" >Analysis of the Pigeonhole Sort Algorithm in Python:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/#Advantages\" >Advantages:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/#Disadvantages\" >Disadvantages:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/#Must_Read\" >Must Read<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/#Conclusion\" >Conclusion:<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-algorithm-for-pigeonhole-sort-in-python\"><span class=\"ez-toc-section\" id=\"Algorithm_for_Pigeonhole_Sort_in_Python\"><\/span>Algorithm for Pigeonhole Sort in Python:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ol class=\"wp-block-list\"><li>At first, we will find the maximum as well as the minimum value in the array. Finding the max and the <a href=\"http:\/\/www.pythonpool.com\/python-min\/\" target=\"_blank\" rel=\"noreferrer noopener\">min<\/a> value, we can easily calculate the range as (max-min +1)<\/li><li>Now, we will create an empty array having the same size as the range.  The space of the array is why this array is known as pigeonholes.<\/li><li>Now, we will <a href=\"http:\/\/www.pythonpool.com\/python-iterate-through-list\/\" target=\"_blank\" rel=\"noreferrer noopener\">iterate<\/a> through the original array and put each element in its respective pigeonhole. The pigeonhole of an element a[i] is calculated as the index a[i]-mini<\/li><li>Lastly, in the initial array, we will reinsert the filled holes<\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-illustration-of-the-algorithm\"><span class=\"ez-toc-section\" id=\"Illustration_of_the_Algorithm\"><\/span>Illustration of the Algorithm:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Let us consider an array having elements as <strong>[12, 16, 19, 10,  9]<\/strong><\/p>\n\n\n\n<p><strong>Maximum element<\/strong> = 19<\/p>\n\n\n\n<p><strong>Minimum element <\/strong>= 9<\/p>\n\n\n\n<p>Thus, <strong>range<\/strong> = ( 19 &#8211; 9 )= 10<\/p>\n\n\n\n<p>Now, we will <strong>create a pigeonhole array<\/strong> having index from 0-10<\/p>\n\n\n\n<p>Now, that the pigeonhole array is created we will put each element from the original array into their respective pigeonhole<\/p>\n\n\n\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter is-resized\"><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/VKhzI.jpg\" alt=\"Example of Pigeonhole Sort in Python\" width=\"612\" height=\"426\"\/><figcaption><em><strong>Pigeonhole Algorithm<\/strong><\/em><strong><em> Illustration<\/em><\/strong><\/figcaption><\/figure><\/div>\n\n\n\n<p>Here, B is the pigeonhole array having index 0-10<\/p>\n\n\n\n<p><strong>In the respective pigeonholes, we will fill the elements from the original array<\/strong><\/p>\n\n\n\n<p>Lastly, in the initial array we will reinsert the filled holes, thus giving a sorted array.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-implementation-of-pigeonhole-sort-algorithm-in-python\"><span class=\"ez-toc-section\" id=\"Implementation_of_Pigeonhole_Sort_Algorithm_in_Python\"><\/span>Implementation of Pigeonhole Sort Algorithm in Python:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\ndef pigeonhole_sort(a):\n    minimum = min(a)\n    maximum = max(a)\n    size = maximum - minimum + 1\n    pigeonholes = &#x5B;0] * size\n    for i in a:\n        pigeonholes&#x5B;i - minimum] += 1\n    j = 0\n    for count in range(size):\n        while pigeonholes&#x5B;count] &gt; 0:\n            pigeonholes&#x5B;count] -= 1\n            a&#x5B;j] = count + minimum\n            j += 1\n             \n \na = &#x5B;12, 16, 19, 10,  9]\nprint(&quot;The array is :&quot;)\nprint(a)\nprint(&quot;Sorted array is :&quot;)\npigeonhole_sort(a)\nprint(a)\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"h-output\">Output:<\/h3>\n\n\n\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"596\" height=\"248\" src=\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/image-66.png\" alt=\"\" class=\"wp-image-6399\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/image-66.png 596w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/image-66-300x125.png 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/image-66-150x62.png 150w\" sizes=\"(max-width: 596px) 100vw, 596px\" \/><figcaption><em><strong>Output for pigeonhole sort<\/strong><\/em><\/figcaption><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-explanation-of-the-code\">explanation of the code:<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>At first, we have found the maximum and minimum value, and from that, we have calculated the size of the pigeonhole array.<\/li><li>After this, for the index corresponding to which the elements are present in the original array, we will insert the value 1 in the pigeonhole array.<\/li><li>And finally, in the original <a href=\"https:\/\/en.wikipedia.org\/wiki\/Array_data_structure\" target=\"_blank\" rel=\"noreferrer noopener\">array<\/a>, we will reinsert the filled holes, thus giving a sorted array.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-analysis-of-the-pigeonhole-sort-algorithm-in-python\"><span class=\"ez-toc-section\" id=\"Analysis_of_the_Pigeonhole_Sort_Algorithm_in_Python\"><\/span>Analysis of the Pigeonhole Sort Algorithm in Python:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Time complexity:<\/strong> O(n+K)<\/li><li><strong>Space complexity: <\/strong>O(n+K)<\/li><\/ul>\n\n\n\n<p><strong>Note:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><em>n &#8211; Size of array<\/em><\/li><li><em>K &#8211; Range of value<\/em><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-advantages\"><span class=\"ez-toc-section\" id=\"Advantages\"><\/span>Advantages:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Pigeonhole sort is a non-comparison based sort making it faster in application<\/li><li>It is a stable sorting algorithm<\/li><li>It performs sorting in linear time<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-disadvantages\"><span class=\"ez-toc-section\" id=\"Disadvantages\"><\/span>Disadvantages:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>It isn&#8217;t easy to know the range of the numbers to sort<\/li><li>This number might only work with zero and positive integers<\/li><\/ul>\n\n\n\n<h2 class=\"has-vivid-red-color has-text-color wp-block-heading\" id=\"h-must-read\"><span class=\"ez-toc-section\" id=\"Must_Read\"><\/span>Must Read<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"http:\/\/www.pythonpool.com\/insertion-sort-python\/\" rel=\"noreferrer noopener\" target=\"_blank\">Insertion Sort in Python [Program, Algorithm, Example]<\/a><\/li><li><a href=\"http:\/\/www.pythonpool.com\/python-bubble-sort\/\" rel=\"noreferrer noopener\" target=\"_blank\">Understanding Python Bubble Sort with examples<\/a><\/li><li><a href=\"http:\/\/www.pythonpool.com\/shell-sort-python\/\">Shell Sort Algorithm and Program in Python<\/a><\/li><li><a href=\"http:\/\/www.pythonpool.com\/python-strand-sort\/\" target=\"_blank\" rel=\"noreferrer noopener\">Understanding Strand Sort in Python With Example<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\"><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 learned about the pigeonhole algorithm. Its implementation in python, its advantages as well as its disadvantages. All <a href=\"http:\/\/www.pythonpool.com\/python-sort-list-of-lists\/\" target=\"_blank\" rel=\"noreferrer noopener\">sorting algorithms<\/a> come with their own pros and cons. If the number of items and its range is similar, the pigeonhole algorithm will be a wise choice.<\/p>\n\n\n\n<p>However, if you have any doubts or questions, do let me know in the comment section below. I will try to help you as soon as possible.<\/p>\n\n\n\n<p><strong><em>Happy Pythoning!<\/em><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will dig into a sorting algorithm known as the pigeonhole sort in Python. So, what exactly is a pigeonhole sort? It &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Pigeonhole Sort in Python With Algorithm and Code Snippet\" class=\"read-more button\" href=\"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/#more-6397\" aria-label=\"More on Pigeonhole Sort in Python With Algorithm and Code Snippet\">Read more<\/a><\/p>\n","protected":false},"author":12,"featured_media":6427,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[15],"tags":[2784,2783],"class_list":["post-6397","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-pigeonhole-python-sort","tag-pigeonhole-sort-animation","infinite-scroll-item"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.1 (Yoast SEO v25.0) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Pigeonhole Sort in Python With Algorithm and Code Snippet - Python Pool<\/title>\n<meta name=\"description\" content=\"Pigeonhole sort in Python is used to sort the lists in which the number of elements is approx equal to the range of possible key values.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Pigeonhole Sort in Python With Algorithm and Code Snippet\" \/>\n<meta property=\"og:description\" content=\"In this article, we will dig into a sorting algorithm known as the pigeonhole sort in Python. So, what exactly is a pigeonhole sort? It is a sorting\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Pool\" \/>\n<meta property=\"article:published_time\" content=\"2020-12-16T07:44:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-06-14T10:30:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-24.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1350\" \/>\n\t<meta property=\"og:image:height\" content=\"650\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Prachee Sao\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:site\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prachee Sao\" \/>\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:\/\/www.pythonpool.com\/python-pigeonhole-sort\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/\"},\"author\":{\"name\":\"Prachee Sao\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/b91d749826b21e606d55cda77d51ef47\"},\"headline\":\"Pigeonhole Sort in Python With Algorithm and Code Snippet\",\"datePublished\":\"2020-12-16T07:44:37+00:00\",\"dateModified\":\"2021-06-14T10:30:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/\"},\"wordCount\":533,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-24.png\",\"keywords\":[\"pigeonhole python sort\",\"pigeonhole sort animation\"],\"articleSection\":[\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/\",\"url\":\"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/\",\"name\":\"Pigeonhole Sort in Python With Algorithm and Code Snippet - Python Pool\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-24.png\",\"datePublished\":\"2020-12-16T07:44:37+00:00\",\"dateModified\":\"2021-06-14T10:30:32+00:00\",\"description\":\"Pigeonhole sort in Python is used to sort the lists in which the number of elements is approx equal to the range of possible key values.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/#primaryimage\",\"url\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-24.png\",\"contentUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-24.png\",\"width\":1350,\"height\":650,\"caption\":\"Python pigeonhole sort\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.pythonpool.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Pigeonhole Sort in Python With Algorithm and Code Snippet\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.pythonpool.com\/#website\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"name\":\"Python Pool\",\"description\":\"Your One-Stop Python Learning Destination\",\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.pythonpool.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.pythonpool.com\/#organization\",\"name\":\"Python Pool\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"contentUrl\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"width\":452,\"height\":185,\"caption\":\"Python Pool\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/pythonpool\",\"https:\/\/www.youtube.com\/c\/pythonpool\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/b91d749826b21e606d55cda77d51ef47\",\"name\":\"Prachee Sao\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d018c3758049ab2511d0772ac1f73c338aaa8c921577f39e0f1e5716fc7efcb4?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d018c3758049ab2511d0772ac1f73c338aaa8c921577f39e0f1e5716fc7efcb4?s=96&d=wavatar&r=g\",\"caption\":\"Prachee Sao\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Pigeonhole Sort in Python With Algorithm and Code Snippet - Python Pool","description":"Pigeonhole sort in Python is used to sort the lists in which the number of elements is approx equal to the range of possible key values.","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:\/\/www.pythonpool.com\/python-pigeonhole-sort\/","og_locale":"en_US","og_type":"article","og_title":"Pigeonhole Sort in Python With Algorithm and Code Snippet","og_description":"In this article, we will dig into a sorting algorithm known as the pigeonhole sort in Python. So, what exactly is a pigeonhole sort? It is a sorting","og_url":"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/","og_site_name":"Python Pool","article_published_time":"2020-12-16T07:44:37+00:00","article_modified_time":"2021-06-14T10:30:32+00:00","og_image":[{"width":1350,"height":650,"url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-24.png","type":"image\/png"}],"author":"Prachee Sao","twitter_card":"summary_large_image","twitter_creator":"@pythonpool","twitter_site":"@pythonpool","twitter_misc":{"Written by":"Prachee Sao","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/#article","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/"},"author":{"name":"Prachee Sao","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/b91d749826b21e606d55cda77d51ef47"},"headline":"Pigeonhole Sort in Python With Algorithm and Code Snippet","datePublished":"2020-12-16T07:44:37+00:00","dateModified":"2021-06-14T10:30:32+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/"},"wordCount":533,"commentCount":0,"publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"image":{"@id":"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-24.png","keywords":["pigeonhole python sort","pigeonhole sort animation"],"articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/","url":"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/","name":"Pigeonhole Sort in Python With Algorithm and Code Snippet - Python Pool","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/#primaryimage"},"image":{"@id":"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-24.png","datePublished":"2020-12-16T07:44:37+00:00","dateModified":"2021-06-14T10:30:32+00:00","description":"Pigeonhole sort in Python is used to sort the lists in which the number of elements is approx equal to the range of possible key values.","breadcrumb":{"@id":"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/#primaryimage","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-24.png","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-24.png","width":1350,"height":650,"caption":"Python pigeonhole sort"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pythonpool.com\/python-pigeonhole-sort\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pythonpool.com\/"},{"@type":"ListItem","position":2,"name":"Pigeonhole Sort in Python With Algorithm and Code Snippet"}]},{"@type":"WebSite","@id":"https:\/\/www.pythonpool.com\/#website","url":"https:\/\/www.pythonpool.com\/","name":"Python Pool","description":"Your One-Stop Python Learning Destination","publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pythonpool.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pythonpool.com\/#organization","name":"Python Pool","url":"https:\/\/www.pythonpool.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/","url":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","contentUrl":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","width":452,"height":185,"caption":"Python Pool"},"image":{"@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/pythonpool","https:\/\/www.youtube.com\/c\/pythonpool"]},{"@type":"Person","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/b91d749826b21e606d55cda77d51ef47","name":"Prachee Sao","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d018c3758049ab2511d0772ac1f73c338aaa8c921577f39e0f1e5716fc7efcb4?s=96&d=wavatar&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d018c3758049ab2511d0772ac1f73c338aaa8c921577f39e0f1e5716fc7efcb4?s=96&d=wavatar&r=g","caption":"Prachee Sao"}}]}},"_links":{"self":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/6397","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/comments?post=6397"}],"version-history":[{"count":7,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/6397\/revisions"}],"predecessor-version":[{"id":13602,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/6397\/revisions\/13602"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media\/6427"}],"wp:attachment":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media?parent=6397"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/categories?post=6397"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/tags?post=6397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}