Re: Optimisation Hints (dict processing and strings)

2005-03-30 Thread Kent Johnson
OPQ wrote: for (2): for k in hash.keys()[:]: # Note : Their may be a lot of keys here if len(hash[k])<2: del hash[k] - use the dict.iter* methods to prevent building a list in memory. You shouldn't use these values directly to delete the entry as this could break the iterator: for key i

Re: Optimisation Hints (dict processing and strings)

2005-03-30 Thread Daniel Dittmar
OPQ wrote: - Try if it isn't faster to iterate using items instead of iterating over keys items are huge lists of numbers. keys are simple small strings. And even if it is faster, how can I find the key back, in order to delete it ? for v in hashh.items(): if len(v)<2: del ???

Re: Optimisation Hints (dict processing and strings)

2005-03-30 Thread Bengt Richter
On 29 Mar 2005 23:41:15 -0800, [EMAIL PROTECTED] (OPQ) wrote: [...] >> > for k in hash.keys()[:]: # Note : Their may be a lot of keys here >> >if len(hash[k])<2: >> > del hash[k] >> >> - Try if it isn't faster to iterate using items instead of iterating >> over keys > >items are huge l

Re: Optimisation Hints (dict processing and strings)

2005-03-30 Thread MyHaz
I posted a question about string concatination just last week. There is plenty of discussion on it, if you just search the group. -- http://mail.python.org/mailman/listinfo/python-list

Re: Optimisation Hints (dict processing and strings)

2005-03-29 Thread OPQ
#For the record, I'm not on premature optimisation anymore. #The code is working. I just want to save hours of computing, without relying to much on C extensions. #Nevertheless, thansk for tips, clarifications and explanations. > longone=longone + char # where len(char)== 1 > > > > I known t

Re: Optimisation Hints (dict processing and strings)

2005-03-29 Thread John Machin
OPQ wrote: > (2)- in a dict mapping a key to a list of int, remove every entrie > where the list of int have of length < 2 > > > So far, my attempts are > for (2): > for k in hash.keys()[:]: # Note : Their may be a lot of keys here >if len(hash[k])<2: > del hash[k] > > > Here again, I th

RE: Optimisation Hints (dict processing and strings)

2005-03-29 Thread Peter Hansen
Thanks for the correction. I didn't pause to think as I wrote that... -Peter > -Original Message- > From: Aaron Bingham [mailto:[EMAIL PROTECTED] > Sent: Tuesday, March 29, 2005 11:24 > To: Peter Hansen > Cc: python-list@python.org > Subject: Re: Optimisation

Re: Optimisation Hints (dict processing and strings)

2005-03-29 Thread Aaron Bingham
Peter Hansen <[EMAIL PROTECTED]> writes: > You've misunderstood the comments about this area. > String concatenation is *not* "time consuming". > *Repeated* concatenations *will become very time > consuming*, along an exponential curve. That's > what the discussions about O(n^2) are referring > t

Re: Optimisation Hints (dict processing and strings)

2005-03-29 Thread Daniel Dittmar
OPQ wrote: for (1): longone=longone + char # where len(char)== 1 I known that string concatenation is time consuming, but a small test on timeit seems to show that packing and creating an array for those 2 elements is equally time consuming - use cStringIO instead - or append all chars to a list

Re: Optimisation Hints (dict processing and strings)

2005-03-29 Thread Peter Hansen
OPQ wrote: I'd happy to have you share some thougts about ultimate optimisations on those 2 topics: (1)- adding one caractere at the end of a string (may be long) longone=longone + char # where len(char)== 1 I known that string concatenation is time consuming, but a small test on timeit seems to sh

Optimisation Hints (dict processing and strings)

2005-03-29 Thread OPQ
Hi all, I'd happy to have you share some thougts about ultimate optimisations on those 2 topics: (1)- adding one caractere at the end of a string (may be long) (2)- in a dict mapping a key to a list of int, remove every entrie where the list of int have of length < 2 So far, my attempts are fo