python 使用sorted方法對二維列表排序


list3 = [['1', '15', '8'], ['1', '14', '2'], ['1', '15', '9'], ['1', '14', '3'], ['1', '16', '0'], ['1', '15', '1'],
          ['1', '16', '2'], ['1', '15', '10'], ['1', '16', '3'], ['1', '15', '12']]


def sort3(list1):
  #對數字列表排序 list2 = sorted(list1, key=(lambda x: [x[0],x[1], x[2]]))
  #以內部的一維列表的下標為0的元素為主,下標為1的元素為次,以下標為2的元素最次,進行排序 print(list2) return list2 def to_int(slist):
  #將字符串列表轉化為數字列表 num_list = [] for i in slist: r = map(eval, i) num_list.append(list(r)) print(num_list) return num_list

num_list2 = to_int(list3)
sort3(num_list2)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM