![]() ![]() There are also a few other features that you might find useful. popleft()) # > Customer # 1 print(ticket_queue) # > deque() append('Customer # 1') ticket_queue.append('Customer # 2') ticket_queue.append('Customer # 3') print(ticket_queue) # > deque() Removing elements: print(ticket_queue. from collections import deque ticket_queue = deque() Adding elements: ticket_queue. pop()) # > Pancake #2 -||- # QUEUE: The syntax is also similar,the only difference is when removing elements you use popleft. pop() print(pancakeStack) # > deque() Get removed element: print(pancakeStack. append('Pancake #3') print(pancakeStack) # > deque() Removing elements: pancakeStack. from collections import deque pancakeStack = deque() Adding elements: pancakeStack. If you need more performance and some extra features there are other options, a popular one is collections deque : # STACK: The syntax is identical (except the deque object), but as mentioned you get better performance. While lists seem to work perfectly fine for your average stack and queue needs. Complexities and Alternative implementations: The original reason ( for me at least) to write this article came when reviewing someone else's code and finding an import for collections deque, the good news is that if you've been following the examples, you already know most of what collections deque does, so what follows is a brief overview. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |