Jonathan Fine writes:

 > Here's a baby example - searching in a nested loop. Suppose we're
 > looking for the word 'apple' in a collection of books. Once we've
 > found it, we stop.

While I was writing a reply, several people replied with very similar
comments, so I won't repeat them.  But these two examples are so
obnoxious I had to post them:

>>> for page in (page for book in books for page in book if 'a' in page):
...  break
... 
>>> page
'abc'
>>> [page for book in books for page in book if 'a' in page][0]
'abc'
>>> 
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/UC5DV2KLXZTRXYBRCAWB7PFODBVNIZDK/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to