0
How i can change dictionary when it iterated in python?
5 Réponses
+ 3
What do you want to change in the dictionary? Key or value?
+ 1
When looping over a dictionary directly, you'd go like this:
for key in d:
d[key]... and then whatever you want to do.
You can't do anything that changes the size of your dict while you're looping over it.
What exactly do you want to do?
+ 1
For example (very simple code:)):
a = {'a': 1, 'b': 2}
for k, v in a.items():
del a[k]