Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #60771

Re: For-each behavior while modifying a collection

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'cursor': 0.09; 'derived': 0.09; 'inserts': 0.09; 'item,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:while': 0.09; 'python': 0.11; '(there': 0.16; '>they': 0.16; 'confuse': 0.16; 'expects': 0.16; 'message-id:@4ax.com': 0.16; 'programmer,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'either.': 0.24; 'url:home': 0.24; 'possibly': 0.26; 'query': 0.26; 'this:': 0.26; 'skip:" 20': 0.27; 'header:X-Complaints- To:1': 0.27; "doesn't": 0.30; 'matching': 0.30; 'code': 0.31; 'that.': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'says': 0.33; 'could': 0.34; 'something': 0.35; 'there': 0.35; 'really': 0.36; 'object,': 0.36; 'method': 0.36; 'charset:us-ascii': 0.36; 'should': 0.36; 'experience,': 0.37; 'received:76': 0.38; 'nov': 0.38; 'to:addr:python-list': 0.38; 'list,': 0.38; 'fact': 0.38; 'rather': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'remove': 0.60; 'middle': 0.60; 'removing': 0.60; 'most': 0.60; 'show': 0.63; 'subject:For': 0.78; 'items,': 0.91; '2013': 0.98
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: For-each behavior while modifying a collection
Date Fri, 29 Nov 2013 11:37:45 -0500
Organization IISS Elusive Unicorn
References <mailman.3360.1385653859.18130.python-list@python.org> <52980885$0$29993$c3e8da3$5496439d@news.astraweb.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host adsl-76-249-16-78.dsl.klmzmi.sbcglobal.net
X-Newsreader Forte Agent 6.00/32.1186
X-No-Archive YES
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3401.1385743058.18130.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1385743058 news.xs4all.nl 15908 [2001:888:2000:d::a6]:60924
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:60771

Show key headers only | View raw


On 29 Nov 2013 03:22:45 GMT, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> declaimed the following:


>Even if there was a counter, how should it be modified? The code you show 
>was this:
>
>def keepByValue(self, key=None, value=[]):
>    for row in self.flows:
>        if not row[key] in value:
>            self.flows.remove(row)
>
>
>What exactly does the remove() method do? How do you know?
>
>self.flows could be *any object at all*, it won't be known until run-
>time. The remove method could do *anything*, that won't be known until 
>runtime either. Just because you, the programmer, expects that self.flows 
>will be a list, and that remove() will remove at most one item, doesn't 
>mean that Python can possibly know that. Perhaps self.flows returns an 
>subclass of list, and remove() will remove all of the matching items, not 
>just one. Perhaps it is some other object, and rather than removing 
>anything, in fact it actually inserts extra items in the middle of the 
>sequence. (There is no law that says that methods must do what they say 
>they do.)
>

	Let's really confuse matters...

	Say "self.flows" is something derived from a database cursor/result
set...

	Then "self.flows.remove(row)" could: 1) remove the row from the
cursor/result set [iterating over a cursor tends, in my experience, to use
up the items]; 2) execute a query to remove the matching row from the
database itself; 3) do both...
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

For-each behavior while modifying a collection Valentin Zahnd <v.zahnd@gmail.com> - 2013-11-28 16:49 +0100
  Re: For-each behavior while modifying a collection Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-29 03:22 +0000
    Re: For-each behavior while modifying a collection Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-11-29 11:37 -0500

csiph-web