What is the output?
d = {'a': 1, 'b': 2}
del d['a']
d['a'] = 3
print(list(d))
- ['b', 'a']
- ['a', 'b']
- ['b']
- ['a', 'b', 'a']
Dicts keep insertion order. Deleting 'a' and adding it again inserts it as a new key at the end.
Play Problem Solving ▸
d = {'a': 1, 'b': 2}
del d['a']
d['a'] = 3
print(list(d))