我有两个列表
list1 =[0.11,0.11,0.22,0.11,0.22]
list2 = [a,o,q,d,e]
我想先按数字排序,然后才按字母排序。我的愿望输出:
list1 =[0.22,0.22,0.11,0.11,0.11] #sort decesding
list2 =[e,q,a,d,o] #sort acesding for first 2 since they have larger num in list 1, thn only sort others (acesding also)
我尝试了以下操作,但它只根据一个标准进行排序
list1, list2 = zip(*sorted(zip(list1,list2), reverse=True))
请帮助 ........
你接近了,试试这个
list1, list2 = zip(*sorted(zip(list1,list2), key=lambda x : x[0], reverse=True))
list1
(0.22, 0.22, 0.11, 0.11, 0.11)
list2
('q', 'e', 'a', 'o', 'd')