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

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

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

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 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 up with was something

Re: List behaviour

2008-05-15 Thread Gabriel
Bruno Desthuilliers bruno.42.desthuilliers at 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':

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

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 to end up with was

Re: List behaviour

2008-05-15 Thread Gabriel
Diez B. Roggisch deets at 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 _

Re: List behaviour

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

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], [], [], [], [], []] I got this

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:  tasks [[1], [], [],

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 expecting to end up with was

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, 12, 13, 14], [15, 16,

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] is b[0] and a[1] is b[1]

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): ... b[i][x] = b[i][x] + 10

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

Re: List behaviour

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