python ascii 排序 sorted默认排序

图片整理

http://www.nowcoder.com/questionTerminal/2de4127fda5e46858aa85d254af43941

大神答案。
sorted对字符串str 对排序默认是按照ascii码进行排序。

while True:
    try:
        print("".join(sorted(input())))
    except:
        break

个人答案,测试时间超过2秒。

while True:
    try:
        in_str=input()
        in_list = [x for x in in_str]
        out_list = sorted(in_list,key = ord)
        out_str =''.join(out_list)
        print(out_str)
    except:
        pass
全部评论
你把你的pass改成break 一样也能过
1 回复 分享
发布于 2020-10-14 23:34

相关推荐

不愿透露姓名的神秘牛友
06-26 14:50
人力小鱼姐:有后面墨迹那两句的时间问题早回答完了
点赞 评论 收藏
分享
06-13 10:15
门头沟学院 Java
想去夏威夷的大西瓜在...:我也是27届,但是我现在研一下了啥项目都没有呀咋办,哎,简历不知道咋写
点赞 评论 收藏
分享
06-10 23:36
已编辑
首都经济贸易大学 C++
点赞 评论 收藏
分享
评论
2
1
分享

创作者周榜

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