3 ms·
The easiest is to never use .keys() or .iterkeys(), and always iterate over the bare dict: for k in dict: ... if k in dict: ... If yo
by andreasvc 11y ago
The easiest is to never use .keys() or .iterkeys(), and always iterate over the bare dict:
for k in dict:
...
if k in dict:
...
If you do need a list of keys, list(dict) has the advantage of working in both Python 2 and 3.