{"id":25525492,"date":"2022-05-27T02:33:23","date_gmt":"2022-05-26T21:03:23","guid":{"rendered":"https:\/\/entri.app\/blog\/?p=25525492"},"modified":"2022-11-22T17:24:52","modified_gmt":"2022-11-22T11:54:52","slug":"stack-and-queue-in-python-using-queue-module","status":"publish","type":"post","link":"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/","title":{"rendered":"Stack and Queue in Python Using Queue Module"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_79_2 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69e0f5299e27b\" class=\"ez-toc-cssicon-toggle-label\"><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><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69e0f5299e27b\"  aria-label=\"Toggle\" \/><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:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/#Queue_Objects\" >Queue Objects<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/#Difference_between_Stack_and_Queue_Data_Structures\" >Difference between Stack and Queue Data Structures<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/#Difference_between_Stack_and_Queue_Data_Structures-2\" >Difference between Stack and Queue Data Structures<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/#Queue_Operations_in_Data_Structure\" >Queue Operations in Data Structure<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/#Different_operations_in_Queue_Data_Structure\" >Different operations in Queue Data Structure.<\/a><\/li><\/ul><\/nav><\/div>\n<p>In Python, it is very easy to implement stack and queue data structures. Stack is called LIFO because Stack works on the principle of &#8220;Last-in, first-out&#8221; and Queue is called FIFO because Queue works on the principle of &#8220;First-in, first-out&#8221;, and the inbuilt functions in Python make the code shorter and simple.<\/p>\n<p>The Queue module implements multi-producer, multi-consumer queues and it is especially useful in threaded programming when information must be exchanged safely between multiple threads. The Queue class in this module implements all the required locking semantics and it depends on the availability of thread support in Python.<\/p>\n<p><a href=\"https:\/\/entri.sng.link\/Bcofz\/w75k\/zvbw\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-25520910 size-full\" src=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square.png\" alt=\"Python and Machine Learning Square\" width=\"345\" height=\"345\" srcset=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square.png 345w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-300x300.png 300w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-150x150.png 150w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-24x24.png 24w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-48x48.png 48w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-96x96.png 96w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-75x75.png 75w\" sizes=\"auto, (max-width: 345px) 100vw, 345px\" \/><\/a><\/p>\n<p>This module implements three types of queue, which differ only in the order in which the entries are retrieved. For FIFO queue, the first tasks added are the first retrieved and for LIFO queue, the most recently added entry is the first retrieved (operating like a stack). And for priority queue, the entries are kept sorted and the lowest valued entry is retrieved first.<\/p>\n<p style=\"text-align: center;\"><strong><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\">Learn Coding in your Language! Enroll Here!<\/a><\/strong><\/p>\n<p>This queue module defines the following classes and exceptions.<\/p>\n<h3>class Queue.Queue(maxsize=0)<\/h3>\n<p>This is a constructor for a FIFO queue. Argument maxsize is an integer that sets the upper bound limit on the number of items that can be placed in the queue. Insertion will block once this size has been reached, until queue items are consumed. If maxsize is less than or equal to zero then the queue size will be infinite.<\/p>\n<h3>class Queue.LifoQueue(maxsize=0)<\/h3>\n<p>This is constructor for a LIFO queue. Argument maxsize is an integer that sets the upperbound limit on the number of items that can be placed in the queue. Insertion will block once this size has been reached, until queue items are consumed. If maxsize is less than or equal to zero then the queue size will be infinite.<\/p>\n<h3>class Queue.PriorityQueue(maxsize=0)<\/h3>\n<p>This is constructor for a priority queue. Argument maxsize is an integer that sets the upperbound limit on the number of items that can be placed in the queue. Insertion will block once this size has been reached, until queue items are consumed. If maxsize is less than or equal to zero then the queue size is infinite.<\/p>\n<h3>exception Queue.Empty<\/h3>\n<p>This line indicate that the exception raised when non-blocking get() (or get_nowait()) is called on a Queue object which is empty.<\/p>\n<h3>exception Queue.Full<\/h3>\n<p>This line indicate that the exception raised when non-blocking put() (or put_nowait()) is called on a Queue object which is full.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Queue_Objects\"><\/span><strong>Queue Objects<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><b>Queue.qsize()<\/b><\/p>\n<p>This function returns the approximate size of the queue.<\/p>\n<p><b>Queue.empty()<\/b><\/p>\n<p>This function returns True if the queue is empty otherwise False. If empty() returns True it doesn&#8217;t guarantee that a subsequent call to put() will not block. Similarly, if empty() returns False it doesn&#8217;t guarantee that a subsequent call to get() will not block.<\/p>\n<p><b>Queue.full()<\/b><\/p>\n<p>Returns True if the queue is full, False otherwise. If full() returns True it doesn&#8217;t guarantee that a subsequent call to get() will not block. Similarly, if full() returns False it doesn&#8217;t guarantee that a subsequent call to put() will not block.<\/p>\n<p><b>Queue.put(item[, block[, timeout]])<\/b><\/p>\n<p>Put item into the queue. If optional args block is true and timeout is None (the default), block if necessary until a free slot is available. If timeout is a positive number, it blocks at most timeout seconds and raises the Full exception if no free slot was available within that time. Otherwise (block is false), put an item on the queue if a free slot is immediately available, else raise the Full exception (timeout is ignored in that case).<\/p>\n<h3>Queue.get([block[, timeout]])<\/h3>\n<p>Remove and return an item from the queue. If optional args block is true and timeout is None (the default), block if necessary until an item is available. If timeout is a positive number, it blocks at most timeout seconds and raises the Empty exception if no item was available within that time. Otherwise (block is false), return an item if one is immediately available, else raise the Empty exception (timeout is ignored in that case).<\/p>\n<h3>Queue.task_done()<\/h3>\n<p>Indicates that a formerly enqueued task is complete. Used by queue consumer threads. For each get() used to fetch a task, a subsequent call to task_done() tells the queue that the processing on the task is complete.<\/p>\n<p>If a join() is currently blocking, it will resume when all items have been processed (meaning that a task_done() call was received for every item that had been put() into the queue).<\/p>\n<p>Raises a ValueError if called more times than there were items placed in the queue.<\/p>\n<h3>Queue.join()<\/h3>\n<p>Blocks until all items in the queue have been gotten and processed.<\/p>\n<p>The count of unfinished tasks goes up whenever an item is added to the queue. The count goes down whenever a consumer thread calls task_done() to indicate that the item was retrieved and all work on it is complete. When the count of unfinished tasks drops to zero, join() unblocks.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Difference_between_Stack_and_Queue_Data_Structures\"><\/span><strong>Difference between Stack and Queue Data Structures<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div class=\"text\">\n<p>A\u00a0stack\u00a0is a linear data structure in which elements can be inserted and deleted only from one side of the list, called the\u00a0top. A stack follows the\u00a0LIFO (Last In First Out) principle, that is , the element inserted at the last is the first element to come out. The insertion of an element into stack is called push\u00a0operation, and deletion of an element from the stack is called\u00a0pop\u00a0operation. In stack we always keep track of the last element present in the list with a pointer called\u00a0top.<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\"><strong>Learn to code from industry experts! Enroll here<\/strong><\/a><\/p>\n<p>The diagrammatic representation of stack is given below:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/media.geeksforgeeks.org\/wp-content\/uploads\/geek-stack-1.png\" alt=\"Stacks\" \/><\/p>\n<p>A queue\u00a0is a linear data structure in which elements can be inserted only from one side of the list called\u00a0rear, and the elements can be deleted only from the other side called the\u00a0front. The queue data structure follows the\u00a0FIFO (First In First Out) principle, that is, the element inserted at first in the list, is the first element to be removed from the list. The insertion of an element in a queue is called an enqueue\u00a0operation and the deletion of an element is called a\u00a0dequeue\u00a0operation. In queue we always maintain two pointers, one pointing to the element which was inserted at the first and still present in the list with the\u00a0front\u00a0pointer and the second pointer pointing to the element inserted at the last with the\u00a0rear\u00a0pointer.<\/p>\n<p>The diagrammatic representation of queue is given below:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/media.geeksforgeeks.org\/wp-content\/uploads\/geek-queue-1.png\" alt=\"Queue\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Difference_between_Stack_and_Queue_Data_Structures-2\"><\/span><strong>Difference between Stack and Queue Data Structures<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<table width=\"100%\">\n<thead>\n<tr>\n<th>Stacks<\/th>\n<th>Queues<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Stacks are based on the LIFO principle, i.e., the element inserted at the last, is the first element to come out of the list.<\/td>\n<td>Queues are based on the FIFO principle, i.e., the element inserted at the first, is the first element to come out of the list.<\/td>\n<\/tr>\n<tr>\n<td>Insertion and deletion in stacks takes place only from one end of the list called the top.<\/td>\n<td>Insertion and deletion in queues takes place from the opposite ends of the list. The insertion takes place at the rear of the list and the deletion takes place from the front of the list.<\/td>\n<\/tr>\n<tr>\n<td>Insert operation is called push operation.<\/td>\n<td>Insert operation of queue is called enqueue operation.<\/td>\n<\/tr>\n<tr>\n<td>Delete operation is called pop operation.<\/td>\n<td>Delete operation of queue is called dequeue operation.<\/td>\n<\/tr>\n<tr>\n<td>In stacks we maintain only one pointer to access the list, called the top, which always points to the last element present in the list.<\/td>\n<td>In queues we maintain two pointers to access the list. The front pointer always points to the first element inserted in the list and is still present, and the rear pointer always points to the last inserted element.<\/td>\n<\/tr>\n<tr>\n<td>Stack is used in solving problems works on recursion.<\/td>\n<td>Queue is used in solving problems having sequential processing.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 class=\"h1\"><span class=\"ez-toc-section\" id=\"Queue_Operations_in_Data_Structure\"><\/span><strong>Queue Operations in Data Structure<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3 class=\"h2\"><strong>What is a Queue?<\/strong><\/h3>\n<p>A queue is a logical group of elements in which updates or changes are introduced at one side (the &#8220;back&#8221;) and existing items are deleted at the opposite end (the &#8220;front&#8221;). When an item is introduced to the queue, it moves from the back to the front, ready to be eliminated next. The queue&#8217;s newly acquired item will have to wait until the collection&#8217;s finish. This way of ordering is also known as first-in-first-out (FIFO) (first-in, first-out).<\/p>\n<p>Operating systems employ a variety of queues to manage things within a system. The next job is frequently planned using a queuing approach in order to run programs as quickly as feasible while servicing the largest number of people possible. Furthermore, while we type, keystrokes might occasionally outweigh the text on the screen. The reason is that the computer is now engaged with other duties. The strokes of keys are queued in a file and eventually shown on the screen in the right sequence.<\/p>\n<p><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-25522670 size-full\" src=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1.png\" alt=\"Python and Machine Learning Rectangle\" width=\"970\" height=\"250\" srcset=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1.png 970w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1-300x77.png 300w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1-768x198.png 768w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1-750x193.png 750w\" sizes=\"auto, (max-width: 970px) 100vw, 970px\" \/><\/a><\/p>\n<h2 class=\"h2\"><span class=\"ez-toc-section\" id=\"Different_operations_in_Queue_Data_Structure\"><\/span><strong>Different operations in Queue Data Structure.<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The various operations of queue in data structure that helps the user to modify and manipulate the data present in the queue are:<\/p>\n<ul class=\"points\">\n<li><strong>Enqueue operation:<\/strong>\u00a0The term &#8220;enqueue&#8221; refers to the act of adding a new element to a queue. Where does a new individual go and wait in a standard queue at a ticket counter to join the queue? The individual walks to the back of the room and takes a seat. A new element in a queue is similarly added at the end of the queue.<\/li>\n<li><strong>Dequeue operation:<\/strong> Dequeue is the process of deleting an item from a queue. We must delete the queue member that was put first since the queue follows the FIFO principle. We will delete the front element and make the element behind it the new front element because the element added initially will naturally be at the head of the queue.<\/li>\n<li><strong>Front Operation:<\/strong>\u00a0This works similarly to the peek operation in stacks in that it returns the value of the first element without deleting it.<\/li>\n<li><strong>isEmpty Operation:<\/strong>\u00a0The isEmpty() function is used to check if the Queue is empty or not.<\/li>\n<li><strong>isFull Operation:<\/strong>\u00a0The isFull() function is used to check if the Queue is full or not.<\/li>\n<\/ul>\n<p style=\"text-align: center;\"><strong><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\">Grab the opportunity to learn Python with Entri! Click Here<\/a><\/strong><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In Python, it is very easy to implement stack and queue data structures. Stack is called LIFO because Stack works on the principle of &#8220;Last-in, first-out&#8221; and Queue is called FIFO because Queue works on the principle of &#8220;First-in, first-out&#8221;, and the inbuilt functions in Python make the code shorter and simple. The Queue module [&hellip;]<\/p>\n","protected":false},"author":111,"featured_media":25525697,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[802,1888],"tags":[],"class_list":["post-25525492","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-articles","category-python-programming"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Stack and Queue in Python Using Queue Module - Entri Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Stack and Queue in Python Using Queue Module - Entri Blog\" \/>\n<meta property=\"og:description\" content=\"In Python, it is very easy to implement stack and queue data structures. Stack is called LIFO because Stack works on the principle of &#8220;Last-in, first-out&#8221; and Queue is called FIFO because Queue works on the principle of &#8220;First-in, first-out&#8221;, and the inbuilt functions in Python make the code shorter and simple. The Queue module [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/\" \/>\n<meta property=\"og:site_name\" content=\"Entri Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/entri.me\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-05-26T21:03:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-22T11:54:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/Stack-and-Queue-in-Python-Using-Queue-Module.png\" \/>\n\t<meta property=\"og:image:width\" content=\"820\" \/>\n\t<meta property=\"og:image:height\" content=\"615\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Feeba Mahin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@entri_app\" \/>\n<meta name=\"twitter:site\" content=\"@entri_app\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Feeba Mahin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/\"},\"author\":{\"name\":\"Feeba Mahin\",\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/person\/f036dab84abae3dcc9390a1110d95d36\"},\"headline\":\"Stack and Queue in Python Using Queue Module\",\"datePublished\":\"2022-05-26T21:03:23+00:00\",\"dateModified\":\"2022-11-22T11:54:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/\"},\"wordCount\":1724,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/entri.app\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/Stack-and-Queue-in-Python-Using-Queue-Module.png\",\"articleSection\":[\"Articles\",\"Python Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/\",\"url\":\"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/\",\"name\":\"Stack and Queue in Python Using Queue Module - Entri Blog\",\"isPartOf\":{\"@id\":\"https:\/\/entri.app\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/Stack-and-Queue-in-Python-Using-Queue-Module.png\",\"datePublished\":\"2022-05-26T21:03:23+00:00\",\"dateModified\":\"2022-11-22T11:54:52+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/#primaryimage\",\"url\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/Stack-and-Queue-in-Python-Using-Queue-Module.png\",\"contentUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/Stack-and-Queue-in-Python-Using-Queue-Module.png\",\"width\":820,\"height\":615,\"caption\":\"Stack and Queue in Python Using Queue Module\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/entri.app\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Programming\",\"item\":\"https:\/\/entri.app\/blog\/category\/python-programming\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Stack and Queue in Python Using Queue Module\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/entri.app\/blog\/#website\",\"url\":\"https:\/\/entri.app\/blog\/\",\"name\":\"Entri Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/entri.app\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/entri.app\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/entri.app\/blog\/#organization\",\"name\":\"Entri App\",\"url\":\"https:\/\/entri.app\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png\",\"contentUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png\",\"width\":989,\"height\":446,\"caption\":\"Entri App\"},\"image\":{\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/entri.me\/\",\"https:\/\/x.com\/entri_app\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/person\/f036dab84abae3dcc9390a1110d95d36\",\"name\":\"Feeba Mahin\",\"url\":\"https:\/\/entri.app\/blog\/author\/feeba123\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Stack and Queue in Python Using Queue Module - Entri Blog","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:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/","og_locale":"en_US","og_type":"article","og_title":"Stack and Queue in Python Using Queue Module - Entri Blog","og_description":"In Python, it is very easy to implement stack and queue data structures. Stack is called LIFO because Stack works on the principle of &#8220;Last-in, first-out&#8221; and Queue is called FIFO because Queue works on the principle of &#8220;First-in, first-out&#8221;, and the inbuilt functions in Python make the code shorter and simple. The Queue module [&hellip;]","og_url":"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/","og_site_name":"Entri Blog","article_publisher":"https:\/\/www.facebook.com\/entri.me\/","article_published_time":"2022-05-26T21:03:23+00:00","article_modified_time":"2022-11-22T11:54:52+00:00","og_image":[{"width":820,"height":615,"url":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/Stack-and-Queue-in-Python-Using-Queue-Module.png","type":"image\/png"}],"author":"Feeba Mahin","twitter_card":"summary_large_image","twitter_creator":"@entri_app","twitter_site":"@entri_app","twitter_misc":{"Written by":"Feeba Mahin","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/#article","isPartOf":{"@id":"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/"},"author":{"name":"Feeba Mahin","@id":"https:\/\/entri.app\/blog\/#\/schema\/person\/f036dab84abae3dcc9390a1110d95d36"},"headline":"Stack and Queue in Python Using Queue Module","datePublished":"2022-05-26T21:03:23+00:00","dateModified":"2022-11-22T11:54:52+00:00","mainEntityOfPage":{"@id":"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/"},"wordCount":1724,"commentCount":0,"publisher":{"@id":"https:\/\/entri.app\/blog\/#organization"},"image":{"@id":"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/#primaryimage"},"thumbnailUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/Stack-and-Queue-in-Python-Using-Queue-Module.png","articleSection":["Articles","Python Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/","url":"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/","name":"Stack and Queue in Python Using Queue Module - Entri Blog","isPartOf":{"@id":"https:\/\/entri.app\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/#primaryimage"},"image":{"@id":"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/#primaryimage"},"thumbnailUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/Stack-and-Queue-in-Python-Using-Queue-Module.png","datePublished":"2022-05-26T21:03:23+00:00","dateModified":"2022-11-22T11:54:52+00:00","breadcrumb":{"@id":"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/#primaryimage","url":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/Stack-and-Queue-in-Python-Using-Queue-Module.png","contentUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/05\/Stack-and-Queue-in-Python-Using-Queue-Module.png","width":820,"height":615,"caption":"Stack and Queue in Python Using Queue Module"},{"@type":"BreadcrumbList","@id":"https:\/\/entri.app\/blog\/stack-and-queue-in-python-using-queue-module\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/entri.app\/blog\/"},{"@type":"ListItem","position":2,"name":"Python Programming","item":"https:\/\/entri.app\/blog\/category\/python-programming\/"},{"@type":"ListItem","position":3,"name":"Stack and Queue in Python Using Queue Module"}]},{"@type":"WebSite","@id":"https:\/\/entri.app\/blog\/#website","url":"https:\/\/entri.app\/blog\/","name":"Entri Blog","description":"","publisher":{"@id":"https:\/\/entri.app\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/entri.app\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/entri.app\/blog\/#organization","name":"Entri App","url":"https:\/\/entri.app\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png","contentUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png","width":989,"height":446,"caption":"Entri App"},"image":{"@id":"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/entri.me\/","https:\/\/x.com\/entri_app"]},{"@type":"Person","@id":"https:\/\/entri.app\/blog\/#\/schema\/person\/f036dab84abae3dcc9390a1110d95d36","name":"Feeba Mahin","url":"https:\/\/entri.app\/blog\/author\/feeba123\/"}]}},"_links":{"self":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts\/25525492","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/users\/111"}],"replies":[{"embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/comments?post=25525492"}],"version-history":[{"count":10,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts\/25525492\/revisions"}],"predecessor-version":[{"id":25547754,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts\/25525492\/revisions\/25547754"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/media\/25525697"}],"wp:attachment":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/media?parent=25525492"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/categories?post=25525492"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/tags?post=25525492"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}