Remove Dictionary Keys
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-keys
Section titled “Sourcery refactoring id: remove-dict-keys”Description:
Section titled “Description:”Removes unnecessary call to keys() when iterating over a dictionary
Before:
Section titled “Before:”for currency in currencies.keys(): process(currency)After:
Section titled “After:”for currency in currencies: process(currency)Explanation:
Section titled “Explanation:”Sometimes when iterating over a dictionary you only need to use the dictionary keys.
In this case the call to keys() is unnecessary, since the default behaviour
when iterating over a dictionary is to iterate over the keys.
The code is now slightly cleaner and easier to read, and avoiding a function call will yield a (small) performance improvement.