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


Groups > comp.lang.python > #63818

Re: L[:]

Date 2014-01-13 10:00 +0100
From Laszlo Nagy <gandalf@shopzeus.com>
Subject Re: L[:]
References <1389375507.21198.YahooMailBasic@web163801.mail.gq1.yahoo.com> <lapspc$vp0$1@ger.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.5398.1389604172.18130.python-list@python.org> (permalink)

Show all headers | 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