Convert month name to month number faster
wiso
gtu2003 at alice.it
Wed Jan 6 07:03:38 EST 2010
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
> write:
>
> xxx = map(month_dict.__getitem__, l)
t = time(); xxx=map(month_dict.__getitem__,l); print time() - t # 0.2
month_list =
("","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
t = time(); xxx=map(month_list.index,l); time() - t # 0.6
More information about the Python-list
mailing list