avatar Bite 45. Keep a queue of last n items

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 my_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!

Login and get coding
go back Beginner level
Bitecoin 2X

790 out of 809 users completed this Bite.
Will you be Pythonista #791 to crack this Bite?
Resolution time: ~37 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 4.24 on a 1-10 difficulty scale.
» Up for a challenge? 💪

Focus on this Bite hiding sidebars, turn on Focus Mode.

Ask for Help