列表排序
#冒泡法
num = [7, 9, 5, 6, 8, 2]
count = len(num)
for i in range(count):
for j in range(i + 1, count):
if num[i] > num[j]:
num[i], num[j] = num[j], num[i]
print("---end---", num)
字典排序
testdict = {'a': 7, 'b': 9, 'c': 5, 'd': 6, 'e':8, 'f':2}
a = sorted(testdict.items(), key=lambda x: x[1])
a1 = sorted(testdict.items(), key=lambda x: x[1], reverse=True)
print("正序:", a)
print("倒序:", a1)
其他方式后续再更新