L[:]

Laszlo Nagy gandalf at shopzeus.com
Mon Jan 13 04:00:46 EST 2014


> 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.




More information about the Python-list mailing list