Remap Mysql tuple to dictionary
Pom
reply at group.invalid
Mon Sep 25 13:24:07 EDT 2006
Fredrik Lundh wrote:
> if you care about performance, and is using a recent Python, you could
yes i do ;-)
> try doing
>
> d1 = dict((row[0], row[1:]) for row in z1)
>
> instead, and see if that runs faster (this uses a generator expression
> instead of a callback and a full list).
>
> </F>
>
I changed it and it saves me some time so I leave it like that!
with 100000 test records:
>>>
dict+map (1, 2, 3) -> {1: (2, 3)}: 1.343 seconds.
dict+gen-expr (1, 2, 3) -> {1: (2, 3)}: 0.861 seconds.
>>>
dict+map (1, 2, 3) -> {1: (2, 3)}: 1.397 seconds.
dict+gen-expr (1, 2, 3) -> {1: (2, 3)}: 0.943 seconds.
with 500000 test records:
>>>
dict+map (1, 2, 3) -> {1: (2, 3)}: 13.297 seconds.
dict+gen-expr (1, 2, 3) -> {1: (2, 3)}: 8.335 seconds.
>>>
dict+map (1, 2, 3) -> {1: (2, 3)}: 14.548 seconds.
dict+gen-expr (1, 2, 3) -> {1: (2, 3)}: 9.793 seconds.
>>>
thank you!!
More information about the Python-list
mailing list