NP11 排序与反转
思路:
sorted(my_list) --- 正序排列;
sorted(my_list,reverse = True) --- 倒叙排列;
my_list.sort() --- 正序排列;
my_list.sort(reverse = True) --- 倒叙排列;
my_list.reverse() --- 反转排列;
reversed(my_list) --- 反转排列;
代码如下:
my_list = ['P','y','t','h','o','n']
print('Here is the original list:')
print(my_list)
print()
print('The result of a temporary reverse order:')
print(sorted(my_list,reverse = True))
print()
print('Here is the original list again:')
print(my_list)
print()
print('The list was changed to:')
my_list.sort(reverse = True)
print(my_list)
print()
print('The list was changed to:')
my_list.reverse()
print(my_list)