Sourcery refactoring id:
any rather than a
found = False for hat in hats: if hat == SOMBRERO: found = True break
found = any(hat == SOMBRERO for hat in hats)
A common pattern is that we need to find if some condition holds for one or all of the items in a collection.
all() built in functions is a more concise way of
doing this than using a
any() will return
True when at least one of the elements evaluates to
all() will return
True only when all the elements evaluate to
These will also short-circuit execution where possible. If the call to
finds an element that evalutes to
True it can return immediately. This can
lead to performance improvements if the code wasn't already short-circuiting.