Pattern: Iterating dictionary via .keys()
instead of itself
Issue: -
Emitted when the keys of a dictionary are iterated through the .keys()
method. It is enough to just iterate through the dictionary itself, as in for key in dictionary
.
Example of incorrect code:
for key in dict.keys():
print "{0} = {1}".format(key, dict[key])
Example of correct code:
for key in dict:
print "{0} = {1}".format(key, dict[key])