Re: Sorting a List of Lists
- From: Bruno Desthuilliers <bdesth.quelquechose@xxxxxxxxxxxxxxxxxxx>
- Date: Wed, 31 Jan 2007 21:43:43 +0100
Paddy a écrit :
On Jan 31, 12:35 pm, Bruno Desthuilliers <bruno.(snip)
Also, using comparison functions is usually not the most efficient way
to do such a sort. In your case, I'd go for a good old
Decorate/sort/undecorate (AKA schwarzian transform):
events = [evt for date, evt in
sorted([(evt[2], evt) for evt in events])]
HTH
I agree with you B., but see the comments here:
http://www.biais.org/blog/index.php/2007/01/28/23-python-sorting-
efficiency
for information on the relative speeds of rolling your own DSU versus
using itemgetter and key=...
Yeps, looks like 2.5 got a real speedup wrt/ itemgetter. Nice to know, and thanks for the link (BTW, this profileit() decorator looks pretty nice too !-)
.
- References:
- Sorting a List of Lists
- From: apotheos
- Re: Sorting a List of Lists
- From: Bruno Desthuilliers
- Re: Sorting a List of Lists
- From: Paddy
- Sorting a List of Lists
- Prev by Date: Re: Python 2.5 Tkinter not configured
- Next by Date: win32com.client
- Previous by thread: Re: Sorting a List of Lists
- Next by thread: Re: Why don't have an object() instance a __dict__ attribute by default?
- Index(es):