-
jeck猫
使用该list.sort()方法。for l in list_of_lists:
l.sort()list_of_lists现在看起来像:[[-1, 0, 9, 34, 42], [-17, 5, 9, 23, 67], [-87, 9, 78, 100, 101]]
-
子衿沉夜
我建议您阅读列表函数sort和sorted,以及列表推导式。最后:list_of_lists = [[42,34,9,-1,0], [-17,9,23,67,5], [101,78,9,100,-87]]list_of_lists = [sorted(sublist) for sublist in list_of_lists]# = [[-1, 0, 9, 34, 42], [-17, 5, 9, 23, 67], [-87, 9, 78, 100, 101]]
-
摇曳的蔷薇
您可以对列表列表进行排序,如下所示:new_list = []for li in list_of_lists: new_list.append(sorted(li))list_of_lists = new_list[[-1, 0, 9, 34, 42], [-17, 5, 9, 23, 67], [-87, 9, 78, 100, 101]]