python列表多关键字排序

时间:2023-01-03 12:07:02


l = ['length_100cm_width_30cm_pict','length_200cm_width_30cm_pict','length_100cm_width_10cm_pict','length_100cm_width_40cm_pict','length_200cm_width_20cm_pict','length_100cm_width_20cm_pict','length_200cm_width_10cm_pict']

l
['length_100cm_width_30cm_pict',
 'length_200cm_width_30cm_pict',
 'length_100cm_width_10cm_pict',
 'length_100cm_width_40cm_pict',
 'length_200cm_width_20cm_pict',
 'length_100cm_width_20cm_pict',
 'length_200cm_width_10cm_pict']

l.sort(key = lambda x:(int(x.split('_')[1][:-2]),int(x.split('_')[3][:-2])))

l
['length_100cm_width_10cm_pict',
 'length_100cm_width_20cm_pict',
 'length_100cm_width_30cm_pict',
 'length_100cm_width_40cm_pict',
 'length_200cm_width_10cm_pict',
 'length_200cm_width_20cm_pict',
 'length_200cm_width_30cm_pict']




参考:http://blog.csdn.net/alvine008/article/details/45367727


                 http://www.cnblogs.com/MUMO/p/5729007.html


 https://www.cnblogs.com/liyuxia713/p/7082091.html