Ron Adam wrote:
> You can sort your grades list however you want. If you want to sort by
> student name instead of student_id, you would use:
>
> # Sort grades list by student name.
> grades.sort(lambda x,y: cmp(students[x[1]][0], students[y[1]][0]))
>
> Assuming the name is in the first field in the student dictionary-value
> tuple. There are probably other ways to do this that are more readable
> or faster.
Assuming that students[x[1]][0] is what you want to sort on, this may
also be written as:
grades.sort(key=lambda x: students[x[1]][0])
It will probably be somewhat faster, but depending on the size of your
data, you may not notice.
STeVe
--
http://mail.python.org/mailman/listinfo/python-list