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

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 ca

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 Dave Angel
cool-RR Wrote in message: > 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

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

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 o

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 o

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

Re: list.insert

2010-07-14 Thread Chris Rebert
On Wed, Jul 14, 2010 at 7:54 AM, Eric J. Van der Velden wrote: > Hi, > > I understand this: > >>>> l=[1,2,3] >>>> l[1:2]=[8,9] >>>> l > [1,8,9,3] > > But how do you do this with list.insert? You can't clobber existing items in

Re: list.insert

2010-07-14 Thread Emile van Sebille
On 7/14/2010 7:54 AM Eric J. Van der Velden said... Hi, I understand this: l=[1,2,3] l[1:2]=[8,9] l [1,8,9,3] But how do you do this with list.insert? >>> l = [1,2,3,4] >>> l[1:2]="" >>> dummy = [l.insert(1,x) for x in reversed([8,9])] Emi

list.insert

2010-07-14 Thread Eric J. Van der Velden
Hi, I understand this: >>> l=[1,2,3] >>> l[1:2]=[8,9] >>> l [1,8,9,3] But how do you do this with list.insert? Thanks, Eric J. -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem with list.insert

2008-08-29 Thread John Machin
On Aug 29, 5:10 pm, SUBHABRATA <[EMAIL PROTECTED]> wrote: > Dear group, > Thanx for your idea to use dictionary instead of a list. Your code is > more or less, OK, some problems are there, I'll debug them. Well, I > feel the insert problem is coming because of the Hindi thing. It's nothing to do w

Re: Problem with list.insert

2008-08-29 Thread SUBHABRATA
Dear group, Thanx for your idea to use dictionary instead of a list. Your code is more or less, OK, some problems are there, I'll debug them. Well, I feel the insert problem is coming because of the Hindi thing. And Python2.5 is supporting Hindi quite fluently. I am writing in Python2.5.1. Best Reg

Re: Problem with list.insert

2008-08-28 Thread Terry Reedy
SUBHABRATA, I recommend you study this excellent response carefully. castironpi wrote: On Aug 28, 11:13 am, SUBHABRATA <[EMAIL PROTECTED]> wrote: -. Instead split up your inputs first thing. trans= { 'a': 'A', 'at': 'AT', 'to': 'TO' } sample= 'a boy at the park walked to the tree' expected= '

Re: Problem with list.insert

2008-08-28 Thread castironpi
On Aug 28, 11:13 am, SUBHABRATA <[EMAIL PROTECTED]> wrote: > Dear Group, > I wrote one program, > There is a dictionary. > There is an input string. > Every word of input string the word is matched against the dictionary > If the word of input string is matched against the dictionary it gives > the

Re: Problem with list.insert

2008-08-28 Thread bearophileHUGS
Subhabrata, it's very difficult for me to understand what your short program has to do, or what you say. I think that formatting and code style are important. So I suggest you to give meaningful names to all your variable names, to remove unused variables (like n), to add blank likes here and ther

Re: Problem with list.insert

2008-08-28 Thread Diez B. Roggisch
Diez B. Roggisch schrieb: SUBHABRATA schrieb: Some people in the room told I am kidding, but I learnt Python from Python docs which gives examples like these, But I write explicit comments, an excerpt from python docs: # Measure some strings: ... a = ['cat', 'window', 'defenestrate'] for x in a

Re: Problem with list.insert

2008-08-28 Thread Diez B. Roggisch
SUBHABRATA schrieb: Some people in the room told I am kidding, but I learnt Python from Python docs which gives examples like these, But I write explicit comments, an excerpt from python docs: # Measure some strings: ... a = ['cat', 'window', 'defenestrate'] for x in a: ... print x, len(x)

Re: Problem with list.insert

2008-08-28 Thread SUBHABRATA
Some people in the room told I am kidding, but I learnt Python from Python docs which gives examples like these, But I write explicit comments, an excerpt from python docs: # Measure some strings: ... a = ['cat', 'window', 'defenestrate'] >>> for x in a: ... print x, len(x) ... cat 3 window 6 d

Re: Problem with list.insert

2008-08-28 Thread Marc 'BlackJack' Rintsch
On Thu, 28 Aug 2008 09:13:00 -0700, SUBHABRATA wrote: > import re > def wordchecker1(n): > # INPUTTING STRING > a1=raw_input("PRINT ONE ENGLISH SENTENCE FOR DICTIONARY CHECK:") > #CONVERTING TO LOWER CASE > a2=a1.lower() > #CONVERTING INTO LIST > a3=a2.split() > #DICTIO

Problem with list.insert

2008-08-28 Thread SUBHABRATA
Dear Group, I wrote one program, There is a dictionary. There is an input string. Every word of input string the word is matched against the dictionary If the word of input string is matched against the dictionary it gives the word of the dictionary. But if it does not find it gives the original wo