Re: Question about `list.insert`

2014-02-07 Thread Peter Otten
cool-RR wrote: > I'm curious. If I append an item to a list from the left using > `list.insert`, will Python always move the entire list one item to the > right (which can be super-slow) or will it check first to see whether it > can just allocate more memory to the left of the list and put the it

Re: Question about `list.insert`

2014-02-06 Thread Asaf Las
On Friday, February 7, 2014 6:52:24 AM UTC+2, Dan Stromberg wrote: > On Thu, Feb 6, 2014 at 3:59 PM, cool-RR wrote: > > I'm pretty sure it'll slide all the existing elements right one > position, and add at the leftmost position just opened up - assuming > you're inserting at position 0. > > As

Re: Question about `list.insert`

2014-02-06 Thread Dan Stromberg
On Thu, Feb 6, 2014 at 3:59 PM, cool-RR wrote: > Hi, > > I'm curious. If I append an item to a list from the left using `list.insert`, > will Python always move the entire list one item to the right (which can be > super-slow) or will it check first to see whether it can just allocate more > me

Re: Question about `list.insert`

2014-02-06 Thread Gregory Ewing
Roy Smith wrote: O(-1). In Soviet Russia, operation performs you! It's rumoured that the PSU is developing a time machine module that can achieve O(-n), but -- https://mail.python.org/mailman/listinfo/python-list

Re: Question about `list.insert`

2014-02-06 Thread Chris Angelico
On Fri, Feb 7, 2014 at 2:29 PM, Rustom Mody wrote: > On Friday, February 7, 2014 8:44:43 AM UTC+5:30, Chris Angelico wrote: >> On Fri, Feb 7, 2014 at 2:00 PM, Roy Smith wrote: >> > Dave Angel wrote: >> >> list does not promise better than O(1) behavior >> > I'm not aware of any list implementati

Re: Question about `list.insert`

2014-02-06 Thread Rustom Mody
On Friday, February 7, 2014 8:44:43 AM UTC+5:30, Chris Angelico wrote: > On Fri, Feb 7, 2014 at 2:00 PM, Roy Smith wrote: > > Dave Angel wrote: > >> list does not promise better than O(1) behavior > > I'm not aware of any list implementations, in any language, that > > promises better than O(1) b

Re: Question about `list.insert`

2014-02-06 Thread Asaf Las
On Friday, February 7, 2014 5:00:56 AM UTC+2, Roy Smith wrote: > In article , > > Dave Angel wrote: > > list does not promise better than O(1) behavior > I'm not aware of any list implementations, in any language, that > promises better than O(1) behavior for any operations. Perhaps there is >

Re: Question about `list.insert`

2014-02-06 Thread Chris Angelico
On Fri, Feb 7, 2014 at 2:11 PM, Tim Chase wrote: > On 2014-02-06 22:00, Roy Smith wrote: >> > list does not promise better than O(1) behavior >> >> I'm not aware of any list implementations, in any language, that >> promises better than O(1) behavior for any operations. Perhaps >> there is O(j),

Re: Question about `list.insert`

2014-02-06 Thread Chris Angelico
On Fri, Feb 7, 2014 at 2:00 PM, Roy Smith wrote: > In article , > Dave Angel wrote: > >> list does not promise better than O(1) behavior > > I'm not aware of any list implementations, in any language, that > promises better than O(1) behavior for any operations. Perhaps there is > O(j), where y

Re: Question about `list.insert`

2014-02-06 Thread Roy Smith
In article , Tim Chase wrote: > On 2014-02-06 22:00, Roy Smith wrote: > > > list does not promise better than O(1) behavior > > > > I'm not aware of any list implementations, in any language, that > > promises better than O(1) behavior for any operations. Perhaps > > there is O(j), where yo

Re: Question about `list.insert`

2014-02-06 Thread Roy Smith
In article , Dave Angel wrote: > list does not promise better than O(1) behavior I'm not aware of any list implementations, in any language, that promises better than O(1) behavior for any operations. Perhaps there is O(j), where you just imagine the operation was performed? -- https://mail

Re: Question about `list.insert`

2014-02-06 Thread Tim Chase
On 2014-02-06 22:00, Roy Smith wrote: > > list does not promise better than O(1) behavior > > I'm not aware of any list implementations, in any language, that > promises better than O(1) behavior for any operations. Perhaps > there is O(j), where you just imagine the operation was performed?

Re: Question about `list.insert`

2014-02-06 Thread Rustom Mody
On Friday, February 7, 2014 8:30:56 AM UTC+5:30, Roy Smith wrote: > Dave Angel wrote: > > > list does not promise better than O(1) behavior > > I'm not aware of any list implementations, in any language, that > promises better than O(1) behavior for any operations. Perhaps there is > O(j), wh

Re: Question about `list.insert`

2014-02-06 Thread Terry Reedy
On 2/6/2014 7:42 PM, MRAB wrote: On 2014-02-06 23:59, cool-RR wrote: Hi, I'm curious. If I append an item to a list from the left using `list.insert`, will Python always move the entire list one item to the right (which can be super-slow) or will it check first to see whether it can just alloca

Re: Question about `list.insert`

2014-02-06 Thread MRAB
On 2014-02-06 23:59, cool-RR wrote: Hi, I'm curious. If I append an item to a list from the left using `list.insert`, will Python always move the entire list one item to the right (which can be super-slow) or will it check first to see whether it can just allocate more memory to the left of the

Re: Question about `list.insert`

2014-02-06 Thread Terry Reedy
On 2/6/2014 6:59 PM, cool-RR wrote: Hi, I'm curious. If I append an item to a list from the left using `list.insert`, will Python always move the entire list one item to the right (which can be super-slow) or will it check first to see whether it can just allocate more memory to the left of the

Question about `list.insert`

2014-02-06 Thread cool-RR
Hi, I'm curious. If I append an item to a list from the left using `list.insert`, will Python always move the entire list one item to the right (which can be super-slow) or will it check first to see whether it can just allocate more memory to the left of the list and put the item there, saving