Remove Dict Items
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: remove-dict-items
Section titled “Sourcery refactoring id: remove-dict-items”Description:
Section titled “Description:”Remove unnecessary calls to dict.items when the values are not used.
Before:
Section titled “Before:”for name, age in people.items(): print("Hi, my name is", name)After:
Section titled “After:”for name in people: print("Hi, my name is", name)Explanation:
Section titled “Explanation:”Calling
dict.items is
only necessary when both the dictionary keys and values are used. When the
values are not used, it is sufficient to iterate over the dictionary keys only.
The code is now easier to read, avoiding an unnecessary call to dict.items,
and removing an unused variable - the dictionary values.