我正在尝试按字母顺序对文本文件的所有单词进行排序。这是我的代码:
filename=input('Write the name of the file :')
fh=open(filename)
wlist=list()
for line in fh:
line=line.rstrip()
ls=line.split()
for w in ls:
if w not in wlist:
wlist.append(w)
print(wlist)
Run Code Online (Sandbox Code Playgroud)
输出没问题,但每当我尝试时,print(wlist.sort())它都会给出“无”作为输出,而不是对 wlist 进行排序。我的代码有什么问题?
提前致谢。