python 字符串排序

地址:

https://www.nowcoder.com/practice/5af18ba2eb45443aa91a11e848aa6723?tpId=37&tqId=21237&rp=1&ru=%2Fta%2Fhuawei&qru=%2Fta%2Fhuawei%2Fquestion-ranking&tab=answerKey

 1 '''
 2 题目描述
 3 给定n个字符串,请对n个字符串按照字典序排列。
 4 输入描述:
 5 输入第一行为一个正整数n(1≤n≤1000),下面n行为n个字符串(字符串长度≤100),字符串中只含有大小写字母。
 6 输出描述:
 7 数据输出n行,输出结果为按照字典序排列的字符串。
 8 示例1
 9 输入
10 9
11 cap
12 to
13 cat
14 card
15 two
16 too
17 up
18 boat
19 boot
20 输出
21 boat
22 boot
23 cap
24 card
25 cat
26 to
27 too
28 two
29 up
30 
31 '''
32 
33 n= int(input())
34 l = []
35 for i in range(n):
36     l.append(input())
37 l.sort()
38 for i in l:
39     print(i)
原文地址:https://www.cnblogs.com/whycai/p/14664456.html