题解 | #排序与反转#

排序与反转

http://www.nowcoder.com/practice/b469ae9eb1b74c029aca052286718938

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)

全部评论

相关推荐

面向对象的火龙果很爱...:去吃一顿炸鸡就走
点赞 评论 收藏
分享
06-20 19:40
中原工学院 Java
网络存储:十几天不会让你拉人办卡就结束了吧?
点赞 评论 收藏
分享
白火同学:能。我当初应届沟通了1200,收简历50,面试10左右吧,加油投吧
投了多少份简历才上岸
点赞 评论 收藏
分享
评论
11
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务