Skip to content

Replace Dict Items with Values

Sourcery refactoring id: replace-dict-items-with-values

Description:

Replace calls to dict.items with dict.values when the keys are not used.

Before:

for key, value in d.items():
    print(value)

After:

for value in d.values():
    print(value)

Explanation:

Calling dict.items is only necessary when both keys and values are needed. However, when the keys are not used, it is cleaner to simply iterate over the dictionary values.