Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.06; 'args': 0.07; 'args)': 0.09; 'logic': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:using': 0.09; 'def': 0.12; 'jan': 0.12; 'args:': 0.16; 'clear.': 0.16; 'created.': 0.16; 'empty,': 0.16; 'empty.': 0.16; 'get,': 0.16; 'ought': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'res': 0.16; 'roy': 0.16; 'wow,': 0.16; 'wrote:': 0.18; 'bit': 0.19; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'requirement.': 0.24; 'header:X-Complaints-To:1': 0.27; 'header :In-Reply-To:1': 0.27; 'chris': 0.29; 'code': 0.31; 'too.': 0.31; 'closer': 0.31; 'controlled': 0.31; "d'aprano": 0.31; 'modified,': 0.31; 'steven': 0.31; 'yes.': 0.31; 'but': 0.35; 'yield': 0.36; 'should': 0.36; 'being': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'changed': 0.39; 'received:org': 0.40; 'read': 0.60; "you're": 0.61; "you'll": 0.62; 'more': 0.64; 'brain': 0.68; 'smith': 0.68; 'safe': 0.72; 'received:fios.verizon.net': 0.84; 'received:108': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Python Iterables struggling using map() built-in Date: Tue, 09 Dec 2014 00:03:33 -0500 References: <004e01d01173$e1641c10$a42c5430$@gmail.com> <5484e3d8$0$13013$c3e8da3$5496439d@news.astraweb.com> <54866372$0$12991$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-108-16-203-145.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: <54866372$0$12991$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1418101434 news.xs4all.nl 2932 [2001:888:2000:d::a6]:52068 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:82175 On 12/8/2014 9:50 PM, Steven D'Aprano wrote: > Roy Smith wrote: > >> Chris Angelico wrote: >>> def myzip(*args): >>> iters = map(iter, args) >>> while iters: >>> res = [next(i) for i in iters] >>> yield tuple(res) >> >> Ugh. When I see "while foo", my brain says, "OK, you're about to see a >> loop which is controlled by the value of foo being changed inside the >> loop". > > Yes. Me too. 99% of the time when you see "while foo", that's what you'll > get, so it's the safe assumption. But it's only an assumption, not a > requirement. When you read a bit more of the code and see that iters isn't > being modified, your reaction ought to be closer "oh wow, that's neat" To me it is a code smell. iters is empty if and only if args is empty. If args is empty, iters should not be created. if args: iters = ... while True ... (return on exception) makes the logic clear. -- Terry Jan Reedy