What is the method for sorting nested lists in Python?

Nested list sorting can be achieved by using the built-in function sorted() in Python together with a lambda function. Below is an example code:

nested_list = [[3, 7], [1, 5], [6, 2], [4, 8]]

# 按嵌套列表中第一个元素排序
sorted_list = sorted(nested_list, key=lambda x: x[0])

print(sorted_list)

In the code above, we have defined a nested list called nested_list, and then sorted it using the sorted() function with a lambda function specifying to sort based on the first element in the nested list. Finally, we print out the sorted list as sorted_list.

bannerAds