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
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
> 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
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
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
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]):
>
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
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:
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 +
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
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:
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
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
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
> 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
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 +
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
> 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
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
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
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
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
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
> 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
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
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.
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
27 matches
Mail list logo