Skip to content

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.

Removes unnecessary call to keys() when iterating over a dictionary

for currency in currencies.keys():
process(currency)
for currency in currencies:
process(currency)

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.