Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!bloom-beacon.mit.edu!bloom-beacon.mit.edu!panix!roy From: Roy Smith Newsgroups: comp.lang.python Subject: Re: Python Iterables struggling using map() built-in Date: Mon, 08 Dec 2014 19:02:00 -0500 Organization: PANIX Public Access Internet and UNIX, NYC Lines: 37 Message-ID: References: <004e01d01173$e1641c10$a42c5430$@gmail.com> <5484e3d8$0$13013$c3e8da3$5496439d@news.astraweb.com> <5485721c$0$2817$c3e8da3$76491128@news.astraweb.com> NNTP-Posting-Host: localhost X-Trace: reader1.panix.com 1418083320 26776 127.0.0.1 (9 Dec 2014 00:02:00 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Tue, 9 Dec 2014 00:02:00 +0000 (UTC) User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) Xref: csiph.com comp.lang.python:82162 In article <5485721c$0$2817$c3e8da3$76491128@news.astraweb.com>, Steven D'Aprano wrote: > On Mon, 08 Dec 2014 11:35:36 +1100, Chris Angelico wrote: > > > On Mon, Dec 8, 2014 at 11:27 AM, Roy Smith wrote: > >> Although, to be honest, I'm wondering if this is more straight-forward > >> (also not tested): > >> > >> def myzip37(*args): > >> if not args: > >> return > >> iters = list(map(iter, args)) > > > > Yes, I prefer this too. It's explicit and clear that passing no > > arguments will yield no values. > > The first version is explicit and clear too. I'm sorry to say this, but > it is true: if you (generic you) don't recognise that > > while iters: > ... > > > skips the while block if iters is an empty list, then *you* have a > problem, not the code. The problem is not that the while body is skipped if iters is falsey. Thats quite clear. The problem is that the looping termination isn't actually controlled by the control variable being exhausted. It's controlled by an exception getting thrown. I'm OK with breaking out of a loop by throwing an exception, but if that's what you're going to do, then make it clear that's the case by doing "while 1" or "while True". Those screams out, "Hey, look at me, I'm an infinite loop", which is your clue that there's something else going on.