avoid for loop calling Generator function
Chris Angelico
rosuav at gmail.com
Mon Feb 22 10:46:33 EST 2016
On Tue, Feb 23, 2016 at 2:38 AM, Arshpreet Singh <arsh840 at gmail.com> wrote:
>> next(filter(print, read_pdf("book.pdf")), None)
>
> Why we are w=using filter here?
It's a beautiful hack. It'll filter according to the "print"
predicate, which always returns None, and will thus filter everything
out. One single call to next() will thus process and print the entire
PDF, and then - since it has a second parameter - return None instead
of raising StopIteration.
Or maybe it's a gross and ugly hack, with the exact same description.
ChrisA
More information about the Python-list
mailing list