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
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
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'
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 repr
I had no clue this was feasible!
Python folks should get the Nobel price !
Larry Bates wrote:
> 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 = ['
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'
>
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
>>> accord
> 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 p
> 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
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
Hi,
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.
Any idea is welcome.
Regards,
Philippe
--
http://mail.python.org/mailman/listinfo/python-lis
11 matches
Mail list logo