--
http://mail.python.org/mailman/listinfo/python-list
python.org
> [mailto:python-list-bounces+ntb837=motorola@python.org] On Behalf Of
> wiso
> Sent: Wednesday, January 06, 2010 4:34 PM
> To: python-list@python.org
> Subject: Convert month name to month number faster
>
> I'm optimizing the inner most loop of my script
On Wed, 06 Jan 2010 12:03:36 +0100, wiso wrote:
> I'm optimizing the inner most loop of my script. I need to convert month
> name to month number. I'm using python 2.6 on linux x64.
According to your own figures below, it takes less than a nanosecond per
lookup, at worst, even using a remarkably
Antoine Pitrou wrote:
> Le Wed, 06 Jan 2010 12:03:36 +0100, wiso a écrit :
>
>
>> from time import time
>> t = time(); xxx=map(to_dict,l); print time() - t # 0.5 t = time();
>> xxx=map(to_if,l); print time() - t # 1.0
>
> Don't define your own function just for attribute access. Instead just
On Jan 6, 9:03 pm, wiso wrote:
> I'm optimizing the inner most loop of my script. I need to convert month
> name to month number. I'm using python 2.6 on linux x64.
>
> month_dict = {"Jan":1,"Feb":2,"Mar":3,"Apr":4, "May":5, "Jun":6,
> "Jul":7,"Aug":8,"Sep":9,"Oct":10,"Nov":11,"Dec":12}
Le Wed, 06 Jan 2010 12:03:36 +0100, wiso a écrit :
> from time import time
> t = time(); xxx=map(to_dict,l); print time() - t # 0.5 t = time();
> xxx=map(to_if,l); print time() - t # 1.0
Don't define your own function just for attribute access. Instead just
write:
xxx = map(month_dict.__geti
Behalf Of
wiso
Sent: Wednesday, January 06, 2010 4:34 PM
To: python-list@python.org
Subject: Convert month name to month number faster
I'm optimizing the inner most loop of my script. I need to convert month
name to month number. I'm using python 2.6 on linux x64.
month_dict = {"Jan&
I'm optimizing the inner most loop of my script. I need to convert month
name to month number. I'm using python 2.6 on linux x64.
month_dict = {"Jan":1,"Feb":2,"Mar":3,"Apr":4, "May":5, "Jun":6,
"Jul":7,"Aug":8,"Sep":9,"Oct":10,"Nov":11,"Dec":12}
def to_dict(name):
return month_dic