Skip to content

Convert any to in

Sourcery refactoring id: convert-any-to-in

Description:

Converts any() functions to simpler in statements

Before:

if any(hat == 'bowler' for hat in hats):
    shout("I have a bowler hat!")

After:

if 'bowler' in hats:
    shout("I have a bowler hat!")

Explanation:

Using Python's in operator simplifies the code and makes it much easier to tell at a glance that you are checking if something is present in the sequence.

Back to top