29 Jul
2020
29 Jul
'20
2:23 p.m.
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'