Re: fastest method

2012-06-21 Thread Jean-Michel Pichavant
david.gar...@gmail.com wrote: I am looking for the fastest way to parse a log file. currently I have this... Can I speed this up any? The script is written to be a generic log file parser so I can't rely on some predictable pattern. def check_data(data,keywords): #get rid of duplicates

Re: fastest method

2012-06-20 Thread david.gar...@gmail.com
I see one issue;) # if last doesn't exist or is greater than current This else doesn't catch the last greater than current: This is a little messy. with open(filename) as f: print "Here is filename:%s" %filename f.seek(0, 2) eof = f.tell() print "Here is eof:%s" %eof if la

Re: fastest method to choose a random element

2008-01-07 Thread caca
> Just for fun, I profiled my answer versus the final answer... This mailing list is awesome! PS:ajaksu, I have to leave now, I hope bukzor's answer was enough to you (at least for the moment) -- http://mail.python.org/mailman/listinfo/python-list

Re: fastest method to choose a random element

2008-01-07 Thread Paddy
On Jan 5, 6:37 am, Paddy <[EMAIL PROTECTED]> wrote: > On Jan 4, 7:55 pm, [EMAIL PROTECTED] wrote: > > > > > Hello, > > This is a question for the best method (in terms of performance > > only) to choose a random element from a list among those that satisfy > > a certain property. > > > This i

Re: fastest method to choose a random element

2008-01-06 Thread bukzor
On Jan 5, 5:36 pm, [EMAIL PROTECTED] wrote: > On Jan 5, 9:50 pm, Paul Hankin <[EMAIL PROTECTED]> wrote: > > > > > On Jan 5, 5:12 pm, Paul Hankin <[EMAIL PROTECTED]> wrote: > > > > On Jan 5, 4:14 pm, [EMAIL PROTECTED] wrote: > > > > > On Jan 5, 5:07 pm, [EMAIL PROTECTED] wrote: > > > > > > Hello, Pa

Re: fastest method to choose a random element

2008-01-06 Thread ajaksu
On Jan 5, 11:36 pm, [EMAIL PROTECTED] wrote: > > This one is good. Someone commented that you destroy the list, but > that can be fixed: > > def pick_random(seq, prop): > L = len(seq) > for i in xrange(L): > r = random.randrange(L - i) > if prop(seq[r]): >

Re: fastest method to choose a random element

2008-01-06 Thread Dustan
On Jan 5, 4:16 am, [EMAIL PROTECTED] wrote: > The warning "The group you are posting to is a Usenet group. Messages > posted to this group will make your email address visible to anyone on > the Internet." means a person, but not a bot, may see my email > address, so it is safe to use my real addre

Re: fastest method to choose a random element

2008-01-05 Thread caca
On Jan 5, 9:50 pm, Paul Hankin <[EMAIL PROTECTED]> wrote: > On Jan 5, 5:12 pm, Paul Hankin <[EMAIL PROTECTED]> wrote: > > > > > On Jan 5, 4:14 pm, [EMAIL PROTECTED] wrote: > > > > On Jan 5, 5:07 pm, [EMAIL PROTECTED] wrote: > > > > > Hello, Paul and Arnaud. > > > > While I think about your answers:

Re: fastest method to choose a random element

2008-01-05 Thread bukzor
On Jan 5, 9:12 am, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote: > > Any other ideas? > > How about this: > > def random_pick(list, property): > L = len(list) > pos = start = random.randrange(L) > while 1: > x = list[pos] > if property(x): return x > pos = (pos +

Re: fastest method to choose a random element

2008-01-05 Thread bukzor
On Jan 5, 8:14 am, [EMAIL PROTECTED] wrote: > On Jan 5, 5:07 pm, [EMAIL PROTECTED] wrote: > > > Hello, Paul and Arnaud. > > While I think about your answers: do you think there is any way to > > avoid shuffle? > > It may take unnecessary long on a long list most of whose elements > > have the prope

Re: fastest method to choose a random element

2008-01-05 Thread Arnaud Delobelle
On Jan 5, 8:50 pm, Paul Hankin <[EMAIL PROTECTED]> wrote: > On Jan 5, 5:12 pm, Paul Hankin <[EMAIL PROTECTED]> wrote: > > > > > On Jan 5, 4:14 pm, [EMAIL PROTECTED] wrote: > > > > On Jan 5, 5:07 pm, [EMAIL PROTECTED] wrote: > > > > > Hello, Paul and Arnaud. > > > > While I think about your answers:

Re: fastest method to choose a random element

2008-01-05 Thread Carl Banks
On Sat, 05 Jan 2008 08:14:46 -0800, caca wrote: > On Jan 5, 5:07 pm, [EMAIL PROTECTED] wrote: >> Hello, Paul and Arnaud. >> While I think about your answers: do you think there is any way to >> avoid shuffle? >> It may take unnecessary long on a long list most of whose elements have >> the propert

Re: fastest method to choose a random element

2008-01-05 Thread Paul Hankin
On Jan 5, 5:12 pm, Paul Hankin <[EMAIL PROTECTED]> wrote: > On Jan 5, 4:14 pm, [EMAIL PROTECTED] wrote: > > > On Jan 5, 5:07 pm, [EMAIL PROTECTED] wrote: > > > > Hello, Paul and Arnaud. > > > While I think about your answers: do you think there is any way to > > > avoid shuffle? > > > It may take u

Re: fastest method to choose a random element

2008-01-05 Thread Paul Hankin
On Jan 5, 4:14 pm, [EMAIL PROTECTED] wrote: > On Jan 5, 5:07 pm, [EMAIL PROTECTED] wrote: > > > Hello, Paul and Arnaud. > > While I think about your answers: do you think there is any way to > > avoid shuffle? > > It may take unnecessary long on a long list most of whose elements > > have the prope

Re: fastest method to choose a random element

2008-01-05 Thread ajaksu
> OTOH, if you do know that the chances are high enough, you can try > choosing items randomly without substitution (adapted from random.py's > sample): Sorry, this works: def randpickuntil(lst, prop=bool): selected = set() n = len(lst) for i in xrange(n): j = int(random() * n

Re: fastest method to choose a random element

2008-01-05 Thread Paul Hankin
On Jan 5, 5:12 pm, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote: > > Any other ideas? > > How about this: > > def random_pick(list, property): >     L = len(list) >     pos = start = random.randrange(L) >     while 1: >         x = list[pos] >         if property(x): return x >         pos = (pos +

Re: fastest method to choose a random element

2008-01-05 Thread Paul Hankin
On Jan 5, 4:14 pm, [EMAIL PROTECTED] wrote: > On Jan 5, 5:07 pm, [EMAIL PROTECTED] wrote: > > > Hello, Paul and Arnaud. > > While I think about your answers: do you think there is any way to > > avoid shuffle? > > It may take unnecessary long on a long list most of whose elements > > have the prope

Re: fastest method to choose a random element

2008-01-05 Thread Martin v. Löwis
> Any other ideas? How about this: def random_pick(list, property): L = len(list) pos = start = random.randrange(L) while 1: x = list[pos] if property(x): return x pos = (pos + 1) % L if pos == start: raise ValueError, "no such item" Regard

Re: fastest method to choose a random element

2008-01-05 Thread ajaksu
Hi there :) On Jan 5, 2:14 pm, [EMAIL PROTECTED] wrote: > On Jan 5, 5:07 pm, [EMAIL PROTECTED] wrote: > > > Hello, Paul and Arnaud. > > While I think about your answers: do you think there is any way to > > avoid shuffle? > > It may take unnecessary long on a long list most of whose elements > > h

Re: fastest method to choose a random element

2008-01-05 Thread caca
On Jan 5, 5:07 pm, [EMAIL PROTECTED] wrote: > Hello, Paul and Arnaud. > While I think about your answers: do you think there is any way to > avoid shuffle? > It may take unnecessary long on a long list most of whose elements > have the property. Umm... You provide nice answers in the case many ele

Re: fastest method to choose a random element

2008-01-05 Thread caca
Hello, Paul and Arnaud. While I think about your answers: do you think there is any way to avoid shuffle? It may take unnecessary long on a long list most of whose elements have the property. -- http://mail.python.org/mailman/listinfo/python-list

Re: fastest method to choose a random element

2008-01-05 Thread Arnaud Delobelle
On Jan 4, 7:55 pm, [EMAIL PROTECTED] wrote: >   Hello, >   This is a question for the best method (in terms of performance > only) to choose a random element from a list among those that satisfy > a certain property. > >   This is the setting: I need to pick from a list a random element > that sati

Re: fastest method to choose a random element

2008-01-05 Thread Paul Hankin
On Jan 4, 7:55 pm, [EMAIL PROTECTED] wrote: >   Hello, >   This is a question for the best method (in terms of performance > only) to choose a random element from a list among those that satisfy > a certain property. > >   This is the setting: I need to pick from a list a random element > that sati

Re: fastest method to choose a random element

2008-01-05 Thread caca
> Caching might help. > > If random_pick is called several times with the same list(s) then > cache the result of > [property(i) for i in a_list] against a_list. > > If random_pick is called several times with list(s) with multiple > instances of list items then cache > property(i) against i for

Re: fastest method to choose a random element

2008-01-04 Thread Paddy
On Jan 4, 7:55 pm, [EMAIL PROTECTED] wrote: > Hello, > This is a question for the best method (in terms of performance > only) to choose a random element from a list among those that satisfy > a certain property. > > This is the setting: I need to pick from a list a random element > that sati

Re: fastest method to choose a random element

2008-01-04 Thread Neil Cerutti
On Jan 4, 2008 3:47 PM, Neil Cerutti <[EMAIL PROTECTED]> wrote: > On Jan 4, 2008 2:55 PM, <[EMAIL PROTECTED]> wrote: > > > Hello, > > This is a question for the best method (in terms of performance > > only) to choose a random element from a list among those that satisfy > > a certain property.

Re: fastest method to choose a random element

2008-01-04 Thread Neil Cerutti
On Jan 4, 2008 2:55 PM, <[EMAIL PROTECTED]> wrote: > Hello, > This is a question for the best method (in terms of performance > only) to choose a random element from a list among those that satisfy > a certain property. I would automatically use random.choice(filter(pred_func, a_list)). You ju