Python Iterables struggling using map() built-in

Chris Angelico rosuav at gmail.com
Sun Dec 7 13:29:55 EST 2014


On Mon, Dec 8, 2014 at 5:27 AM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> On Dec 7, 2014 8:31 AM, "Ned Batchelder" <ned at nedbatchelder.com> wrote:
>> NOTE: THIS EXAMPLE IS HORRIBLE.  This code is crazy-confusing, and should
>> never have been used as an example of iteration. It layers at least three
>> iterations on top of each other, making it very difficult to see what is
>> going on.  It uses "while iters" where "while True" would do exactly the
>> same thing (iters will never be false).
>
> That's not quite correct; the "while iters" actually guards against the case
> where the passed args are empty. With no sub-iterators, no StopIteration
> would ever be raised, and the result would be an infinite generator of empty
> tuples. The "while iters" makes it return immediately instead.
>
> So it seems this example is even more confusing than you thought.

I'm actually glad PEP 479 will break this kind of code. Gives a good
excuse for rewriting it to be more readable.

ChrisA



More information about the Python-list mailing list