我有一个包含这样的句子的输入文件:

I like apples
My mother is called Anna.


我将这些句子转移到列表中,然后删除长度小于3的单词。

我已经试过了:

with open("fis.txt", "r", encoding="utf8") as f:
    lst = [w.lower() for w in f.readlines() if len(w) >= 3]
    print(lst)


但这给了我['i like apples', 'my mother is called anna.']

我想获得['like apples', 'mother called anna.']

这里似乎是什么问题?

最佳答案

尝试:

with open("fis.txt", "r", encoding="utf8") as f:
    print( [" ".join(j for j in w.split() if len(j) >= 3 ) for w in f.readlines() ] )


输出:

['like apples', 'mother called Anna.']

08-20 02:20