sort one list using the values from another list
Alex Martelli
aleaxit at yahoo.com
Sun Feb 26 20:25:23 EST 2006
Ron Adam <rrr at ronadam.com> wrote:
...
> Considering the number time I sort keys after getting them, It's the
> behavior I would prefer. Maybe a more dependable dict.sortedkeys()
> method would be nice. ;-)
sorted(d) is guaranteed to do exactly the same thing as sorted(d.keys())
AND to be faster (would be pretty weird if it weren't faster...!).
E.g., ...:
helen:~ alex$ python -mtimeit -s'd=dict(enumerate("tarazoplay"))'
'sorted(d.keys())'
100000 loops, best of 3: 6.82 usec per loop
helen:~ alex$ python -mtimeit -s'd=dict(enumerate("tarazoplay"))'
'sorted(d)'
100000 loops, best of 3: 5.98 usec per loop
Alex
More information about the Python-list
mailing list