Python去除文档中重复的值,并按英文顺序输出 f = open('名单.txt', 'r') line = f.readlines() line = set(line) line = sorted(line,key= lambda i:i[0]) for i in line: new = i.rstrip("\n") if i==line[len(line)-1]: print(new) else: print(new,end=",") 名单.txt 啦啦啦 吼吼吼 嘤嘤嘤 锵锵锵 啊啊啊 不不不