sorted(iterable[, key][, reverse])
从 iterable 中的项目返回新的排序列表。
有两个可选参数,必须指定为关键字参数。
key 指定一个参数的函数,用于从每个列表元素中提取比较键:key=str.lower。默认值为 None (直接比较元素)。
reverse 是一个布尔值。如果设置为 True,那么列表元素将按照每个比较反转进行排序。
- You will be sorting the following list by each element’s second letter, a to z. Create a function to use when sorting, called second_let. It will take a string as input and return the second letter of that string. Then sort the list, create a variable called sorted_by_second_let and assign the sorted list to it. Do not use lambda.
ex_lst = ['hi', 'how are you', 'bye', 'apple', 'zebra', 'dance']
def second_let(strings):
return strings[1]
sorted_by_second_let = sorted(