[Tutor] Manipulate list in place or append to a new list

bob gailer bgailer at gmail.com
Sun Nov 2 01:23:23 CET 2008


Sander Sweers wrote:
> Hi,
>
> What is the better way to process data in a list? 

Depends on what you mean by "better". Could mean faster, smaller, more 
readable, or ?? Get clear on your goals.

> Make the changes in place, for example
>
> somelist = [1,2,3,4]
>
> for x in range(len(somelist)):
>     somelist[x] = somelist[x] + 1
>
> Or would making a new list like
>
> somelist = [1,2,3,4]
> newlist = []
>
> for x in somelist:
>     newlist.append(x + 1)
>
> Or is there another way of doing this kind of things. Pointers to
> online resources are most welcome :-)
>   

Take a look at Numerical Python http://numpy.scipy.org/, which works 
much like APL:

 >>> /print a/

[1 2 3]

 >>> /print a + 3/

[4 5 6]




-- 
Bob Gailer
Chapel Hill NC 
919-636-4239

When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?



More information about the Tutor mailing list