Is there a way to sort a lot of lists without having to write:
list.sort(list1)
list.sort(list2)
list.sort(list3)
...
for every single list? It is very tedious when you have a lot of lists
Is there a way to sort a lot of lists without having to write:
list.sort(list1)
list.sort(list2)
list.sort(list3)
...
for every single list? It is very tedious when you have a lot of lists
Probably best to use a for
-loop:
lists = [1, 2, -1], [2, 0, 6], [91, 3, 82]
for l in lists: l.sort()
list1, list2, list3 = lists
Now each list is sorted accordingly.
You could of course map
it, but that's overkill since you'll also need to expand it into a list with list
and dump away the resulting None
s produced as a side-effect:
_ = list(map(list.sort, lists))
you don't even Combine your lists to a named variable, so the code takes only 2 lines
l1 = [6,5,4,3,2,1]
l2 = [16,9,4,1]
#start of code
for my_l in [l1,l2]:
list.sort(my_l)
#stop of code
print l1
print l2