We use Python 3.6

go back Level: Beginner (img: BG / score: 2) level Bite 45. Keep a queue of last n items

51 out of 53 users completed this Bite ...
Will you be Pythonista #52 to crack this Bite?
Average Bite difficulty 1-10 rating: 3.67
» You can do it! 😌

How about writing a queue that holds the last 5 items?

Queue follows First-In-First-Out methodology, i.e., the data item stored first will be accessed first. A real-world example of queue can be a single-lane one-way road, where the vehicle enters first, exits first. More real-world examples can be seen as queues at the ticket windows and bus-stops. [source]

Complete the queue function to return a queue-like data type that keeps the last n items.

Check the standard library to see how you can do this in the shortest/most efficient way.

See an example output below and the tests that check for various values of n. Have fun!

Github login button