「Python」sortedでリストの数値を小さい順に並べる
書式
sorted(リスト名)
使用例
# coding: utf-8
cft = [320, 121, 456,23]
res = sorted(cft)
print("古いリスト")
print (cft)
print("新しいリスト")
print (res)
結果
古いリスト
[320, 121, 456, 23]
新しいリスト
[23, 121, 320, 456]
Coding Changes the World
書式
sorted(リスト名)
使用例
# coding: utf-8
cft = [320, 121, 456,23]
res = sorted(cft)
print("古いリスト")
print (cft)
print("新しいリスト")
print (res)
結果
古いリスト
[320, 121, 456, 23]
新しいリスト
[23, 121, 320, 456]