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

2008-11-02 Thread Kent Johnson
On Sun, Nov 2, 2008 at 12:41 PM, spir <[EMAIL PROTECTED]> wrote: > Sander Sweers a écrit : >>> 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 c

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

2008-11-02 Thread spir
Sander Sweers a écrit : On Sun, Nov 2, 2008 at 13:32, Kent Johnson <[EMAIL PROTECTED]> wrote: Use a list comprehension: somelist = [ x+1 for x in somelist ] Got it. Note that this creates a new list, replacing the one that was in somelist. If you need to actually modify somelist in place (ra

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

2008-11-02 Thread Kent Johnson
On Sun, Nov 2, 2008 at 9:13 AM, Sander Sweers <[EMAIL PROTECTED]> wrote: > On Sun, Nov 2, 2008 at 13:32, Kent Johnson <[EMAIL PROTECTED]> wrote: >> 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 some

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

2008-11-02 Thread Sander Sweers
On Sun, Nov 2, 2008 at 13:32, Kent Johnson <[EMAIL PROTECTED]> wrote: > Use a list comprehension: > somelist = [ x+1 for x in somelist ] Got it. > 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 someli

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

2008-11-02 Thread Kent Johnson
On Sat, Nov 1, 2008 at 5:40 PM, Sander Sweers <[EMAIL PROTECTED]> wrote: > Hi, > > What is the better way to process data in a list? 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

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

2008-11-02 Thread Sander Sweers
On Sun, Nov 2, 2008 at 01:23, bob gailer <[EMAIL PROTECTED]> 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 p

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

2008-11-01 Thread bob gailer
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)): somel

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

2008-11-01 Thread spir
Sander Sweers a écrit : Hi, What is the better way to process data in a list? 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:

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

2008-11-01 Thread Sander Sweers
Hi, What is the better way to process data in a list? 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