Re: deque as default list behaviour

2019-03-03 Thread Chris Angelico
On Sun, Mar 3, 2019 at 10:12 PM Abdur-Rahmaan Janhangeer wrote: > > i can be wrong but i guess that inserting at the begining does not cause > troubles as insertion at index 0 is constant (time does not scale with number > of data) > In a deque? Correct. But the price of that is reduced efficie

Re: deque as default list behaviour

2019-03-03 Thread Abdur-Rahmaan Janhangeer
i can be wrong but i guess that inserting at the begining does not cause troubles as insertion at index 0 is constant (time does not scale with number of data) Abdur-Rahmaan Janhangeer http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ Mauritius -- https://mail.python.org/mailman/l

Re: deque as default list behaviour

2019-03-02 Thread Chris Angelico
On Sun, Mar 3, 2019 at 6:17 PM Abdur-Rahmaan Janhangeer wrote: > > simple question; why does the normal list not exhibit a deque behaviour > (left insertion)? Because it's a lot less efficient. If you want that behaviour, you CAN still insert into a list at position zero, but it's going to be slo

deque as default list behaviour

2019-03-02 Thread Abdur-Rahmaan Janhangeer
simple question; why does the normal list not exhibit a deque behaviour (left insertion)? -- Abdur-Rahmaan Janhangeer http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ Mauritius -- https://mail.python.org/mailman/listinfo/python-list

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], [], [], [], []

List behaviour

2008-05-15 Thread Gabriel
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

List behaviour

2006-05-17 Thread barberomarcelo
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): ... b[i][x] = b[i][x] + 10 ... >>> b [[11, 1