Re: List insertion cost

2009-07-22 Thread Diez B. Roggisch
Lucas P Melo wrote: > Hello, > I would like to know how much it costs to insert an element into a list > using this operation: > a[2:2] = [ 1 ] > i. e, what is the complexity of the operation above (given that len(a) = > n)? O(n) I'd say. You need to copy nearly the whole list, and sometimes re-a

Re: List insertion cost

2009-07-21 Thread Lucas P Melo
Robert Kern wrote: O(n). Python lists are contiguous arrays in memory, and everything after the insertion point needs to be moved. Raymond Hettinger has a good talk about the implementation of Python lists and other container objects. http://www.youtube.com/watch?v=hYUsssClE94 http://www.pyco

Re: List insertion cost

2009-07-21 Thread Robert Kern
On 2009-07-21 14:21, Lucas P Melo wrote: Hello, I would like to know how much it costs to insert an element into a list using this operation: a[2:2] = [ 1 ] i. e, what is the complexity of the operation above (given that len(a) = n)? O(n). Python lists are contiguous arrays in memory, and every

Re: List insertion cost

2009-07-21 Thread Daniel Stutzbach
On Tue, Jul 21, 2009 at 2:21 PM, Lucas P Melo wrote: > I would like to know how much it costs to insert an element into a list > using this operation: > a[2:2] = [ 1 ] > i. e, what is the complexity of the operation above (given that len(a) = > n)? > O(n) If you want O(log n), you can use the b

List insertion cost

2009-07-21 Thread Lucas P Melo
Hello, I would like to know how much it costs to insert an element into a list using this operation: a[2:2] = [ 1 ] i. e, what is the complexity of the operation above (given that len(a) = n)? Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: list insertion question

2007-04-16 Thread Paul Rubin
[EMAIL PROTECTED] writes: > hi > i have a list (after reading from a file), say > data = [ 'a','b','c','d','a','b','e','d'] > > I wanted to insert a word after every 'a', and before every 'd'. so i > use enumerate this list: > for num,item in enumerate(data): > if "a" in item: > data.in

Re: list insertion question

2007-04-16 Thread attn . steven . kuo
On Apr 16, 6:05 pm, [EMAIL PROTECTED] wrote: > hi > i have a list (after reading from a file), say > data = [ 'a','b','c','d','a','b','e','d'] > > I wanted to insert a word after every 'a', and before every 'd'. so i > use enumerate this list: > for num,item in enumerate(data): > if "a" in item

Re: list insertion question

2007-04-16 Thread [EMAIL PROTECTED]
On Apr 17, 9:47 am, Michael Hoffman <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > hi > > i have a list (after reading from a file), say > > data = [ 'a','b','c','d','a','b','e','d'] > > > I wanted to insert a word after every 'a', and before every 'd'. so i > > use enumerate this list:

Re: list insertion question

2007-04-16 Thread Michael Hoffman
[EMAIL PROTECTED] wrote: > hi > i have a list (after reading from a file), say > data = [ 'a','b','c','d','a','b','e','d'] > > I wanted to insert a word after every 'a', and before every 'd'. so i > use enumerate this list: > for num,item in enumerate(data): > if "a" in item: > data.inse

list insertion question

2007-04-16 Thread eight02645999
hi i have a list (after reading from a file), say data = [ 'a','b','c','d','a','b','e','d'] I wanted to insert a word after every 'a', and before every 'd'. so i use enumerate this list: for num,item in enumerate(data): if "a" in item: data.insert(num+1,"aword") if "d" in item:

Re: list insertion

2005-08-27 Thread Randy Bush
>>hold = self.next >>self.next = DaClass(value) >>self.next.next = hold >> >> but i suspect (from print statement insertions) that the result >> is not as i expect. as the concept and code should be very >> common, as i am too old for pride, i thought i would ask. > I think you're fine

Re: list insertion

2005-08-27 Thread Bengt Richter
On Tue, 23 Aug 2005 20:58:11 -0700, Randy Bush <[EMAIL PROTECTED]> wrote: >i am trying to insert into a singly linked list > >hold = self.next >self.next = DaClass(value) >self.next.next = hold > >but i suspect (from print statement insertions) that the result >is not as i expect. as

Re: list insertion

2005-08-24 Thread Randy Bush
>> hold = self.next >> self.next = DaClass(value) >> self.next.next = hold > shouldn't that last line be this? > self.next.prev = hold single threaded list > What did you expect, and what did you ovserve? i will try to distill a case randy -- http://mail.python.org/mailman/l

Re: list insertion

2005-08-24 Thread Ross Wilson
On Tue, 23 Aug 2005 20:58:11 -0700, Randy Bush wrote: > i am trying to insert into a singly linked list > > hold = self.next > self.next = DaClass(value) > self.next.next = hold > > but i suspect (from print statement insertions) that the result > is not as i expect. as the concept

Re: list insertion

2005-08-24 Thread Sybren Stuvel
Randy Bush enlightened us with: > hold = self.next > self.next = DaClass(value) > self.next.next = hold shouldn't that last line be this? self.next.prev = hold > but i suspect (from print statement insertions) that the result is > not as i expect. What did you expect, and wha

Re: list insertion

2005-08-23 Thread Jordan Rastrick
What you've posted looks right, more or less. To get any sort of meaningful feedback, you really need to post a full version of your code, including the print statements, what's being printed, and why you think this shows the code is not working. What you've shown is far too little for anybody els

list insertion

2005-08-23 Thread Randy Bush
i am trying to insert into a singly linked list hold = self.next self.next = DaClass(value) self.next.next = hold but i suspect (from print statement insertions) that the result is not as i expect. as the concept and code should be very common, as i am too old for pride, i thought i