PyBites Python Tip / Get 4 weekly tips

When to use a deque over a list

A collections.deque is a list-like container with fast appends and pops on either end:

Copy the code

Subscribe to our Python tips to copy the code

Spread the word

Check out more resources

Login to get more resources

Bite Exercise

Bite 45. Keep a queue of last n items

Get all our Python tips

Get our full collection of 250 (and growing) Python tips, each with more details / explanations.

Buy the book

"The discussions are succinct yet thorough enough to give you a solid grasp of the particular problem. I just wish I would have had this book when I started learning Python." - Daniel H

"Bob and Julian are the masters at aggregating these small snippets of code that can really make certain aspects of coding easier." - Jesse B

"This is now my favourite first Python go-to reference." - Anthony L

"Do you ever go on one of those cooking websites for a recipe and have to scroll for what feels like an eternity to get to the ingredients and the 4 steps the recipe actually takes? This is the opposite of that." - Sergio S