Re: Sorting x lists based on one list ... maybe an example would make sense:

2005-05-18 Thread Peter Otten
Philippe C. Martin wrote: :-) Thanks, the lists will evolve and are also stored in 'csv' format in external files at one point. I cannot use dictionaries because I need to control the sorting (hash). In this specific case, list 1 represents students with their information, list 2

Re: Sorting x lists based on one list ... maybe an example would make sense:

2005-05-18 Thread Ron Adam
Philippe C. Martin wrote: Another way would be to merge the three lists into one of 3-tuples, sort, and unmerge, similarly to the DSU pattern -- which raises the question: why are you using three lists in the first place? :-) Thanks, the lists will evolve and are also stored in 'csv' format

Re: Sorting x lists based on one list ... maybe an example would make sense:

2005-05-18 Thread Steven Bethard
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

Re: Sorting x lists based on one list ... maybe an example would make sense:

2005-05-18 Thread Ron Adam
Steven Bethard wrote: Ron Adam wrote: grades.sort(lambda x,y: cmp(students[x[1]][0], students[y[1]][0])) 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]) Yes, I figured there was a

Re: Sorting x lists based on one list ... maybe an example would make sense:

2005-05-17 Thread Philippe C. Martin
l1 = ['a','b','c'] l2 = ['toto','titi','tata'] # 'toto' refers to 'a', 'titi' to b' l3 = ['foo','bar','doe'] # 'foo' refers to 'a' I want to reverse sort l1 and have l2 and l3 follow accordingly. Regards, Philippe Philippe C. Martin wrote: Hi, I'm looking for an easy

Re: Sorting x lists based on one list ... maybe an example would make sense:

2005-05-17 Thread Peter Otten
Philippe C. Martin wrote: I'm looking for an easy algorithm - maybe Python can help: I start with X lists which intial sort is based on list #1. I want to reverse sort list #1 and have all other lists sorted accordingly. One way, using a helper list with indices: l1 = ['a','b','c'] l2 =

Re: Sorting x lists based on one list ... maybe an example would make sense:

2005-05-17 Thread Philippe C. Martin
Another way would be to merge the three lists into one of 3-tuples, sort, and unmerge, similarly to the DSU pattern -- which raises the question: why are you using three lists in the first place? :-) Thanks, the lists will evolve and are also stored in 'csv' format in external files at one

Re: Sorting x lists based on one list ... maybe an example would make sense:

2005-05-17 Thread Philippe C. Martin
I will look at that merge/unmerge thing Peter Otten wrote: Philippe C. Martin wrote: I'm looking for an easy algorithm - maybe Python can help: I start with X lists which intial sort is based on list #1. I want to reverse sort list #1 and have all other lists sorted accordingly. One

Re: Sorting x lists based on one list ... maybe an example would make sense:

2005-05-17 Thread Larry Bates
Why not merge the lists together using zip() and then sort. info=zip(l1, l2, l3) info.sort() info.reverse Larry Bates Philippe C. Martin wrote: l1 = ['a','b','c'] l2 = ['toto','titi','tata'] # 'toto' refers to 'a', 'titi' to b' l3 = ['foo','bar','doe'] # 'foo' refers to 'a'