This question already has answers here:
case-insensitive list sorting, without lowercasing the result?
                                
                                    (7个答案)
                                
                        
                                6年前关闭。
            
                    
我有这两个列表,我用zip合并它们,然后我想对它们排序,但是它给了我这个结果(Ard,Ger,Sla,ard),而我想成为(ard,Ard,Ger,Sla)。任何的想法?

N = ["ard","Ard","Ger","Sla"]
L = ["7","4","2","3"]
x=zip(N,L)
x.sort()
for i in x:
    print i[0]

最佳答案

传递key参数进行排序:

x.sort(key=lambda (a, b): (a.lower(), b))


输出为:

Ard
ard
Ger
Sla

10-04 12:54