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


Groups > comp.lang.python > #63818 > unrolled thread

Re: L[:]

Started byLaszlo Nagy <gandalf@shopzeus.com>
First post2014-01-13 10:00 +0100
Last post2014-01-13 10:00 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#63818 — Re: L[:]

FromLaszlo Nagy <gandalf@shopzeus.com>
Date2014-01-13 10:00 +0100
SubjectRe: L[:]
Message-ID<mailman.5398.1389604172.18130.python-list@python.org>
> 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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web