多个参数
在上一个练习中,您通过 help() 查看文档来识别可选参数。现在,您将据此修改 sorted() 函数的行为。
在 IPython Shell 中输入 help(sorted),查看 sorted() 的文档。
您会看到 sorted() 接受 3 个参数:iterable、key 和 reverse。在本练习中,您只需要指定 iterable 和 reverse,不需要 key。
我们已为您创建了两个列表。
您能把它们拼接在一起,并按降序排序吗?
本练习是课程的一部分
Python 入门
练习说明
- 使用
+将first和second的内容合并为一个新列表:full。 - 调用
sorted()作用于full,并将reverse参数设为True。将排序后的列表保存为full_sorted。 - 最后打印
full_sorted。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Create lists first and second
first = [11.25, 18.0, 20.0]
second = [10.75, 9.50]
# Paste together first and second: full
full = ____ + ____
# Sort full in descending order: full_sorted
full_sorted = ____
# Print out full_sorted
____