612553 (1) [Avatar] Offline
#1
On page 395, the following solution has been given. What is the difference between the two methods?

TRY THIS: SORTING LISTS Suppose that you have a list in which each element is
in turn a list: [[1, 2, 3], [2, 1, 3], [4, 0, 1]]. If you want to sort
this list by the second element in each list, so that the result is [[4, 0, 1],
[2, 1, 3], [1, 2, 3]], what function would you write to pass as the key
value to the sort() method?
>>> the_list = [[1, 2, 3], [2, 1, 3], [4, 0, 1]]
>>> the_list.sort(key=lambda x: x[1])
>>> the_list
[[4, 0, 1], [2, 1, 3], [1, 2, 3]]
or
>>> the_list = [[1, 2, 3], [2, 1, 3], [4, 0, 1]]
>>> the_list.sort(key=lambda x: x[1])
>>> the_list
[[4, 0, 1], [2, 1, 3], [1, 2, 3]]