Re: List behaviour

2008-05-15 Thread Lie
On May 15, 5:08 pm, Gabriel <[EMAIL PROTECTED]> wrote: > Hi all > > Just wondering if someone could clarify this behaviour for me, please? > > >>> tasks = [[]]*6 > >>> tasks > > [[], [], [], [], [], []]>>> tasks[0].append(1) > >>> tasks > > [[1], [1], [1], [1], [1], [1]] > > Well what I was expecti

Re: List behaviour

2008-05-15 Thread Gabriel
virgilio.it> writes: > >>> tasks = [ [] for x in xrange(6) ] > >>> tasks[0].append(1) > >>> tasks > [[1], [], [], [], [], []] > >>> > Thanks, Bockman -- http://mail.python.org/mailman/listinfo/python-list

Re: List behaviour

2008-05-15 Thread Gabriel
Diez B. Roggisch nospam.web.de> writes: > So instead of creating a list of list by the *-operator that only multiplies > the references (which is fine immutable objects like strings or numbers), > you need to explicitly create new lists, e.g. with a list-comprehension: > > tasks = [[] for _ in x

Re: List behaviour

2008-05-15 Thread Gabriel
Bruno Desthuilliers websiteburo.invalid> writes: > The problem here is that your first statement > > #>>> tasks = [[]]*6 > > creates a list (task) containing 6 references to the *same* (empty) list > object. You can check this easily using the identity test operator 'is': > > If you want 6

Re: List behaviour

2008-05-15 Thread A.T.Hofkamp
On 2008-05-15, Gabriel <[EMAIL PROTECTED]> wrote: > Hi all > > Just wondering if someone could clarify this behaviour for me, please? > tasks = [[]]*6 tasks > [[], [], [], [], [], []] tasks[0].append(1) tasks > [[1], [1], [1], [1], [1], [1]] > > Well what I was expecting to end

Re: List behaviour

2008-05-15 Thread bockman
On 15 Mag, 12:08, Gabriel <[EMAIL PROTECTED]> wrote: > Hi all > > Just wondering if someone could clarify this behaviour for me, please? > > >>> tasks = [[]]*6 > >>> tasks > > [[], [], [], [], [], []]>>> tasks[0].append(1) > >>> tasks > > [[1], [1], [1], [1], [1], [1]] > > Well what I was expecting

Re: List behaviour

2008-05-15 Thread Diez B. Roggisch
Gabriel wrote: > Hi all > > Just wondering if someone could clarify this behaviour for me, please? > tasks = [[]]*6 tasks > [[], [], [], [], [], []] tasks[0].append(1) tasks > [[1], [1], [1], [1], [1], [1]] > > Well what I was expecting to end up with was something like: > 

Re: List behaviour

2008-05-15 Thread Bruno Desthuilliers
Gabriel a écrit : Hi all Just wondering if someone could clarify this behaviour for me, please? tasks = [[]]*6 tasks [[], [], [], [], [], []] tasks[0].append(1) tasks [[1], [1], [1], [1], [1], [1]] Well what I was expecting to end up with was something like: >>> tasks [[1], [], [], [], []

Re: List behaviour

2006-05-17 Thread barberomarcelo
Thank you very much. It was clear. -- http://mail.python.org/mailman/listinfo/python-list

Re: List behaviour

2006-05-17 Thread Mike Kent
When you did: b = a[:] b was then a copy of a, rather than just a reference to the same a. But what does a contain? It contains two sublists -- that is, it contains references to two sublists. So b, which is now a copy of a, contains copies of the two references to the same two sublists. What y

Re: List behaviour

2006-05-17 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote: > Maybe I'm missing something but the latter is not the behaviour I'm > expecting: > a = [[1,2,3,4], [5,6,7,8]] b = a[:] b > [[1, 2, 3, 4], [5, 6, 7, 8]] a == b > True a is b > False for i in range(len(b)): > ... for x in range(4): > ...

Re: List behaviour

2006-05-17 Thread Heiko Wundram
Am Mittwoch 17 Mai 2006 17:06 schrieb [EMAIL PROTECTED]: > Maybe I'm missing something but the latter is not the behaviour I'm > > expecting: > >>> a = [[1,2,3,4], [5,6,7,8]] > >>> b = a[:] > >>> b > > [[1, 2, 3, 4], [5, 6, 7, 8]] > > >>> a == b > > True > > >>> a is b > > False > Try an: >>> a[0