[Tutor] iterate list items as lvalue

2007-08-22 Thread János Juhász
Dear All, I would like to thanks for your responds. Ricardo Aráoz wrote: Kent Johnson wrote: > Dave Kuhlman wrote: >> Consider the following: >> >> >>> array = [1,2,3,4,5] >> >>> array2 = array >> >>> array = [i * 2 for i in array] >> >>> array >> [2, 4, 6,

Re: [Tutor] iterate list items as lvalue

2007-08-20 Thread Ricardo Aráoz
Kent Johnson wrote: > Dave Kuhlman wrote: >> Consider the following: >> >> >>> array = [1,2,3,4,5] >> >>> array2 = array >> >>> array = [i * 2 for i in array] >> >>> array >> [2, 4, 6, 8, 10] >> >>> array2 >> [1, 2, 3, 4, 5] >> >> So, did you want array2 to change, or no

Re: [Tutor] iterate list items as lvalue

2007-08-20 Thread Kent Johnson
Dave Kuhlman wrote: > Consider the following: > > >>> array = [1,2,3,4,5] > >>> array2 = array > >>> array = [i * 2 for i in array] > >>> array > [2, 4, 6, 8, 10] > >>> array2 > [1, 2, 3, 4, 5] > > So, did you want array2 to change, or not? > > Here is a solution that

Re: [Tutor] iterate list items as lvalue

2007-08-20 Thread Dave Kuhlman
On Mon, Aug 20, 2007 at 03:14:24PM -0300, Ricardo Ar?oz wrote: [snip] > > You just work on a generated modified list. > > > > foo = range(1,6) > > for i in [x*2 for x in foo]: > >do_whatever_you_want_with(i) > > > > What about : > > array = [1,2,3,4,5] > array = [i * 2 for i in array] >

Re: [Tutor] iterate list items as lvalue

2007-08-20 Thread Ricardo Aráoz
Noufal Ibrahim wrote: > János Juhász wrote: >> Dear Tutors! >> >> I know a python list is a mutable object. > array = [1,2,3,4,5] >> So I can modify any item in it. > for index in range(len(array)): array[index] *= 2 >> ... > array >> [2, 4, 6, 8, 10] >> >> So I typed this: > for i

Re: [Tutor] iterate list items as lvalue

2007-08-20 Thread Trilok Khairnar
IL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Noufal Ibrahim Sent: Monday, August 20, 2007 8:29 PM To: János Juhász Cc: tutor@python.org Subject: Re: [Tutor] iterate list items as lvalue János Juhász wrote: > Dear Tutors! > > I know a python list is a mutable object. >>>>

Re: [Tutor] iterate list items as lvalue

2007-08-20 Thread Noufal Ibrahim
János Juhász wrote: > Dear Tutors! > > I know a python list is a mutable object. array = [1,2,3,4,5] > > So I can modify any item in it. for index in range(len(array)): array[index] *= 2 > ... array > [2, 4, 6, 8, 10] > > So I typed this: for item in array: item *= 2 > ...

Re: [Tutor] iterate list items as lvalue

2007-08-20 Thread Alan Gauld
"János Juhász" <[EMAIL PROTECTED]> wrote > So I can modify any item in it. > >>> for index in range(len(array)): array[index] *= 2 > ... > >>> array > [2, 4, 6, 8, 10] > > So I typed this: > >>> for item in array: item *= 2 This is equivalent to index = 0 while index < len(array): item = a

[Tutor] iterate list items as lvalue

2007-08-20 Thread János Juhász
Dear Tutors! I know a python list is a mutable object. >>> array = [1,2,3,4,5] So I can modify any item in it. >>> for index in range(len(array)): array[index] *= 2 ... >>> array [2, 4, 6, 8, 10] So I typed this: >>> for item in array: item *= 2 ... >>> array [1, 2, 3, 4, 5] It confused me a