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

Sander Sweers sander.sweers at gmail.com
Sun Nov 2 11:43:36 CET 2008


On Sun, Nov 2, 2008 at 01:23, bob gailer <bgailer at gmail.com> wrote:
>> 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.

Inexperienced beginner programmer asking more experienced programmer
what they would choose and maybe why... Goal, learning best
practises.for pythoin progtramming.

>> 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 :-)

Thanks for you encouraging feedback.

Greets
Sander


More information about the Tutor mailing list