[Tutor] Manipulate list in place or append to a new list
sander.sweers at gmail.com
Sun Nov 2 14:13:54 CET 2008
On Sun, Nov 2, 2008 at 13:32, Kent Johnson <kent37 at tds.net> wrote:
> Use a list comprehension:
> somelist = [ x+1 for x in somelist ]
> Note that this creates a new list, replacing the one that was in
> somelist. If you need to actually modify somelist in place (rare) then
> use somelist[:] = [ x+1 for x in somelist ]
> which creates a new list, then replaces the *contents* of somelist
> with the contents of the new list.
In what (rare) situation would you use this?
This page helped. Especially the link to the 'Reset your brain'
article is very interesting.
More information about the Tutor