Skip to content

Replace Dict Items with Values

Documentation Index

Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt

Use this file to discover all available pages before exploring further.

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

Section titled “Sourcery refactoring id: replace-dict-items-with-values”

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

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

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.