开始使用免费开始使用

多个参数

在上一个练习中,您通过 help() 查看文档来识别可选参数。现在,您将据此修改 sorted() 函数的行为。

在 IPython Shell 中输入 help(sorted),查看 sorted()文档

您会看到 sorted() 接受 3 个参数:iterablekeyreverse。在本练习中,您只需要指定 iterablereverse,不需要 key

我们已为您创建了两个列表。

您能把它们拼接在一起,并按降序排序吗?

本练习是课程的一部分

Python 入门

查看课程

练习说明

  • 使用 +firstsecond 的内容合并为一个新列表: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
____
编辑并运行代码