Python Data Structure and Algorithms Tutorial
Python Data Structure & Algorithms Useful Resources
Selected Reading
- Python - Algorithm Justifications
- Python - Amortized Analysis
- Python - Algorithm Classes
- Python - Big-O Notation
- Python - Algorithm Analysis
- Python - Graph Algorithms
- Python - Searching Algorithms
- Python - Sorting Algorithms
- Python - Backtracking
- Python - Recursion
- Python - Divide and Conquer
- Python - Algorithm Design
- Python - Graphs
- Python - Heaps
- Python - Search Tree
- Python - Binary Tree
- Python - Hash Table
- Python - Advanced Linked list
- Python - Dequeue
- Python - Queue
- Python - Stack
- Python - Linked Lists
- Python - Maps
- Python - Sets
- Python - Matrix
- Python - 2-D Array
- Python - Dictionary
- Python - Tuples
- Python - Lists
- Python - Arrays
- Python - DS Environment
- Python - DS Introduction
- Python - DS Home
Python Data Structure & Algorithms Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Python - Dequeue
Python - Dequeue
A double-ended queue, or deque, supports adding and removing elements from either end. The more commonly used stacks and queues are degenerate forms of deques, where the inputs and outputs are restricted to a single end.
Example
import collections DoubleEnded = collections.deque(["Mon","Tue","Wed"]) DoubleEnded.append("Thu") print ("Appended at right - ") print (DoubleEnded) DoubleEnded.appendleft("Sun") print ("Appended at right at left is - ") print (DoubleEnded) DoubleEnded.pop() print ("Deleting from right - ") print (DoubleEnded) DoubleEnded.popleft() print ("Deleting from left - ") print (DoubleEnded)
Output
When the above code is executed, it produces the following result −
Appended at right - deque([ Mon , Tue , Wed , Thu ]) Appended at right at left is - deque([ Sun , Mon , Tue , Wed , Thu ]) Deleting from right - deque([ Sun , Mon , Tue , Wed ]) Deleting from left - deque([ Mon , Tue , Wed ])Advertisements