小编Tan*_*med的帖子

在列表中对文件的单词进行排序

我正在尝试按字母顺序对文本文件的所有单词进行排序。这是我的代码:

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 进行排序。我的代码有什么问题?

提前致谢。

python sorting list

1
推荐指数
1
解决办法
37
查看次数

标签 统计

list ×1

python ×1

sorting ×1