Python組み込み関数sorted
filter

sorted組み込み関数

reversed

イテラブルから並べ替えた新しいリストを返します。

構文

sorted(iterable, key?, reverse?)

使用例

下記の値を入力するとサンプルに即時反映されます。

nums
result
sorted
print
words
key
nums = [3, 1, 4, 1, 5, 9]
result = sorted(nums)
print(result)  # [1, 1, 3, 4, 5, 9]
print(nums)    # [3, 1, 4, 1, 5, 9]  (원본 유지)

words = ["banana", "apple", "cherry"]
print(sorted(words, key=len))
# ['apple', 'banana', 'cherry']