Is this is an efficient and pythonic way to see if any item in an iterable is true for a certain attribute?
Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Underwater World
--
Chapters
00:00 Question
00:46 Accepted answer (Score 12)
00:59 Thank you
--
Full question
https://stackoverflow.com/questions/1188...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python
#avk47
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Underwater World
--
Chapters
00:00 Question
00:46 Accepted answer (Score 12)
00:59 Thank you
--
Full question
https://stackoverflow.com/questions/1188...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python
#avk47
ACCEPTED ANSWER
Score 12
You should use the built-in function any():
any_item_is_whatever = any(item.is_whatever() for item in items)