[Tutor] str.split and quotes

Marilyn Davis marilyn at deliberate.com
Fri Apr 8 18:16:30 CEST 2005


On Fri, 8 Apr 2005, Kent Johnson wrote:

> Marilyn Davis wrote:
> > Is there a reason to prefer one over the other?  Is one faster?  I
> > compiled my regular expression to make it quicker.
> 
> The only way to know which is faster is to time them both. The timeit module makes it pretty easy to 
> do this.
> 
> Here is a simple example of using timeit for a different problem; you can adapt it to your own needs:

Thank you so much again.

This will be handy.

Marilyn

> 
> d = dict( ((i,i,i), i) for i in range(1000))
> 
> def withItems(d):
>      for k,v in d.iteritems():
>          pass
> 
> 
> def withKeys(d):
>      for k in d:
>          d[k]
> 
> 
> from timeit import Timer
> 
> for fn in [withItems, withKeys]:
>      name = fn.__name__
>      timer = Timer('%s(d)' % name, 'from __main__ import d, %s' % name)
>      print name, timer.timeit(1000)
> 
> 
> Kent
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

-- 



More information about the Tutor mailing list