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


Groups > comp.lang.python > #63818

Re: L[:]

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <gandalf@shopzeus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.042
X-Spam-Evidence '*H*': 0.92; '*S*': 0.00; 'modify': 0.07; 'clean.': 0.09; 'iterate': 0.09; 'mailscanner,': 0.16; 'silly': 0.16; 'modification': 0.16; 'code.': 0.18; 'header:User-Agent:1': 0.23; 'case.': 0.24; 'header:In-Reply-To:1': 0.27; 'scanned': 0.29; 'another': 0.32; 'something': 0.35; 'there': 0.35; 'believed': 0.36; 'received:192.168.2': 0.37; 'list': 0.37; 'to:addr:python- list': 0.38; 'list,': 0.38; 'to:addr:python.org': 0.39; 'called': 0.40; 'dangerous': 0.60; 'viruses': 0.61; 'name:': 0.61; 'within': 0.65
Date Mon, 13 Jan 2014 10:00:46 +0100
From Laszlo Nagy <gandalf@shopzeus.com>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0
MIME-Version 1.0
To python-list@python.org
Subject Re: L[:]
References <1389375507.21198.YahooMailBasic@web163801.mail.gq1.yahoo.com> <lapspc$vp0$1@ger.gmane.org>
In-Reply-To <lapspc$vp0$1@ger.gmane.org>
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-shopzeus-MailScanner-Information Please contact the ISP for more information
X-shopzeus-MailScanner-ID 361428895C53.AA487
X-shopzeus-MailScanner Found to be clean
X-shopzeus-MailScanner-From gandalf@shopzeus.com
X-Spam-Status No
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.5398.1389604172.18130.python-list@python.org> (permalink)
Lines 16
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1389604172 news.xs4all.nl 2831 [2001:888:2000:d::a6]:40511
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:63818

Show key headers only | View raw


> Unless L is aliased, this is silly code.
There is another use case. If you intend to modify a list within a for 
loop that goes over the same list, then you need to iterate over a copy. 
And this cannot be called an "alias" because it has no name:

for idx,item in enumerate(L[:]):
    # do something with L here, including modification



-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

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


Thread

Re: L[:] Laszlo Nagy <gandalf@shopzeus.com> - 2014-01-13 10:00 +0100

csiph-web