KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I want to create a list that will contain the last 5 values entered into it. Here is an example: >>> l = [] >>> l.append('apple') >>> l.append('orange') >>> l.append('grape') >>> l.append('banana') >>> l.append('mango') >>> print(l) ['apple', 'orange', 'grape', 'banana', 'mango'] >>> l.append('kiwi') >>> print(l) # only 5 items in list ['orange', 'grape', 'banana', 'mango', 'kiwi'] So, in Python, is there any way to achieve what is demonstrated above? The variable does not need to be a list, I just used it as an example.
Tags (comma-separated)
Save Edits
Cancel