Python学习者在这里。所以我有一个 wordlist.txt 文件,每行一个单词。我想过滤掉以特定字母开头和结尾的特定单词。但是在我的 wordlist.txt 中,单词是用它们的出现次数列出的。
例如:
food 312
freak 36
cucumber 1
这是我的代码
wordList = open("full.txt","r", encoding="utf-8")
word = wordList.read().splitlines()
for i in word:
if i.startswith("h") and i.endswith("e"):
print(i)
但是由于列表中的每个项目最后都有数字,我无法过滤正确的单词。我不知道如何省略这些数字。