Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'modify': 0.04; 'needed,': 0.05; 'append': 0.07; 'deletes': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'stack,': 0.09; 'python': 0.11; 'jan': 0.11; 'appends': 0.16; 'iterating': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'wrote:': 0.16; ';-)': 0.18; '(or': 0.21; 'am,': 0.23; 'header:In-Reply- To:1': 0.24; 'implemented': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'this.': 0.28; 'subject:/': 0.29; 'appending': 0.29; 'queue': 0.29; 'search.': 0.29; 'terry': 0.29; 'to:addr:python-list': 0.35; 'list': 0.35; 'but': 0.36; 'subject:: ': 0.37; 'ok,': 0.37; 'front': 0.38; 'received:org': 0.38; 'end': 0.39; 'to:addr:python.org': 0.39; 'where': 0.40; 'subject:good': 0.84; 'received:fios.verizon.net': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: zip as iterator and bad/good practices Date: Fri, 12 Jun 2015 19:27:44 -0400 References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-98-114-97-173.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 15 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1434151715 news.xs4all.nl 2863 [2001:888:2000:d::a6]:48066 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:92566 On 6/12/2015 11:00 AM, Fabien wrote: > is it a bad practice > to interactively modify the list you are iterating over? One needs care. Appending to the end of the list is OK, unless you append a billion items or so ;-) Appending to the end of a queue while *removing* items from the front of the queue, where the queue resizes itself at the front as needed, is standard for breadth-first search. A deque.Deque can be used for this. Depth-first search appends to and deletes from the end (or top) of a stack, but this is NOT forward-iteration as implemented by Python iterators. -- Terry Jan Reedy