Skip to content

Instantly share code, notes, and snippets.

@aahnik
Created January 2, 2021 22:36
Show Gist options
  • Save aahnik/033e285c36a361eab0127e5557a55992 to your computer and use it in GitHub Desktop.
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
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