Simplify Generator
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: simplify-generator
Section titled “Sourcery refactoring id: simplify-generator”Description:
Section titled “Description:”An identity generator (a for a in coll) can be replaced directly with the
collection coll
Before:
Section titled “Before:”if any(hat for hat in wardrobe.hats): print("I have a hat!")After:
Section titled “After:”if any(wardrobe.hats): print("I have a hat!")Explanation:
Section titled “Explanation:”The expression (x for x in y) is a generator that returns all of the elements
of y. If being passed into a function like any or all that takes a generator
or sequence, it can simply be replaced by y which is much clearer.