Partition Recursive

macm moura.mario at gmail.com
Fri Dec 24 08:32:47 EST 2010


Thanks all


In [11]: reps = 5
In [12]: t = Timer("url = 'http://docs.python.org/dev/library/
stdtypes.html? highlight=partition#str.partition' ;sp =
re.compile('(//?|[;?:@=&#.])'); filter(len, sp.split(url))", 'import
re')
In [13]: print sum(t.repeat(repeat=reps, number=1)) / reps
4.94003295898e-05

In [65]: t = Timer("url = 'http://docs.python.org/dev/library/
stdtypes.html? highlight=partition#str.partition' ;sp =
re.compile('(//?|[;?:@=&#.])'); filter(None, sp.split(url))", 'import
re')
In [66]: print sum(t.repeat(repeat=reps, number=1)) / reps
3.50475311279e-05


Ian with None is a litle fast, thanks kj!

Hi Mr. James, speed is always important. But ok re is fine. (but could
be e-07)

In next step I'll go to cython to win something.

Regards

Mario



On Dec 24, 3:33 am, Ian Kelly <ian.g.ke... at gmail.com> wrote:
> On 12/23/2010 10:03 PM, kj wrote:
>
> >>>> import re # sorry
> >>>> sp = re.compile('(//?|[;?:@=&#.])')
> >>>> filter(len, sp.split(url))
>
> Perhaps I'm being overly pedantic, but I would likely have written that
> as "filter(None, sp.split(url))" for the same reason that "if string:"
> is generally preferred to "if len(string):".
>
> Cheers,
> Ian




More information about the Python-list mailing list