Skip to content

Files

Latest commit

 

History

History
26 lines (16 loc) · 615 Bytes

consider-iterating-dictionary.md

File metadata and controls

26 lines (16 loc) · 615 Bytes

Pattern: Iterating dictionary via .keys() instead of itself

Issue: -

Description

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])

Further Reading