Refactor any(item for item in items if item in container)
into any(item in container for item in items)
#7998
Closed
brettcannon
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
Hi, this is not equivalent if some items are falsy. >>> items = [True, False]
>>> container = [False]
>>> any(item for item in items if item in container)
False
>>> any(item in container for item in items)
True |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Came up in a code review for
any(p for p in parts if p in s)
. With no assignment expression or any need to know which or how many items match since the loop variant doesn't leak out of the generator expression, there's no need to condition theany()
call on succeeding via which items matched.Beta Was this translation helpful? Give feedback.
All reactions