Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这两个列表,我通过 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参数进行排序:
key
x.sort(key=lambda (a, b): (a.lower(), b))
输出是:
Ard ard Ger Sla