The Python Oracle

Is this is an efficient and pythonic way to see if any item in an iterable is true for a certain attribute?

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Quiet Intelligence

--

Chapters
00:00 Is This Is An Efficient And Pythonic Way To See If Any Item In An Iterable Is True For A Certain Att
00:35 Accepted Answer Score 12
00:44 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)