直接上代码
c_list = sorted(c_list, key=lambda x: (x[1],x[0]))
【需求】针对c_list,按照字母表进行排序,先按tuple中第二个元素排序,当相同时,按tuple中第一个元素排序
c_list结构为:( (ci1, cou1, (lat1,lon1)), (ci2, cou2, (lat2,lon2) ), ...)
(以下为试错过程)
看了很多教程都是这么写的
c_list = sorted(c_list, key=lambda x: (x[1], -x[0]))
报错:bad operand type for unary -: 'str'
解决方式:去掉-