Re: Sorting a multidimensional array by multiple keys
- From: Thomas Krüger <newsgroups@xxxxxxxxxxxxxxxxx>
- Date: Sat, 31 Mar 2007 14:53:11 +0200
Rehceb Rotkiv schrieb:
can I sort a multidimensional array in Python by multiple sort keys? A
litte code sample would be nice!
You can pass a function as argument to the sort method of a list.
The function should take two arguments and return -1, 0 or 1 as
comparison result. Just like the cmp function.
This will objects in list obj_lst by their id attributes:
def sorter(a, b):
return cmp(a.id, b.id)
obj_lst.sort(sorter)
Thomas
.
- References:
- Sorting a multidimensional array by multiple keys
- From: Rehceb Rotkiv
- Sorting a multidimensional array by multiple keys
- Prev by Date: Re: os.system questions
- Next by Date: Need help with python and pyxml on AIX
- Previous by thread: Sorting a multidimensional array by multiple keys
- Next by thread: Re: Sorting a multidimensional array by multiple keys
- Index(es):