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”Description:
Section titled “Description:”Replace calls to
dict.items with
dict.values
when the keys are not used.
Before:
Section titled “Before:”for key, value in d.items(): print(value)After:
Section titled “After:”for value in d.values(): print(value)Explanation:
Section titled “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.