Created
January 2, 2021 22:36
-
-
Save aahnik/033e285c36a361eab0127e5557a55992 to your computer and use it in GitHub Desktop.
When you just want to keep the last n added values to a dictionary. Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var = {} | |
count = 1 | |
limit = 10 | |
while True: | |
data = input('enter data ') | |
var.update({count:data}) | |
print(var) | |
l = len(var) | |
exceeding = l- limit | |
if exceeding > 0: | |
for i in var: | |
del var[i] | |
break | |
count += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment