n=int(input()) arr=[] for i in range(n): arr.append(input()) arr.sort() for i in range(n): print(arr[i])
直接用sort()即可,对于字符串类型的列表,sort()方法默认就是按字典序升序的