Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Day01-20/16.函数使用进阶.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ print(new_nums) # [144, 64, 3600, 2704]
```python
old_strings = ['in', 'apple', 'zoo', 'waxberry', 'pear']
new_strings = sorted(old_strings)
print(new_strings) # ['apple', 'in', 'pear', waxberry', 'zoo']
print(new_strings) # ['apple', 'in', 'pear', 'waxberry', 'zoo']
```

上面的代码对大家来说并不陌生,但是如果希望根据字符串的长度而不是字母表顺序对列表元素排序,我们可以向`sorted`函数传入一个名为`key`的参数,将`key`参数赋值为获取字符串长度的函数`len`,这个函数我们在之前的课程中讲到过,代码如下所示。
Expand Down