这是我的单词表。(实际上我使用的是一个大列表。)
banana
fish
scream
screaming
suncream
suncreams
我想扩大s'cream
。它必须只匹配suncream
。
不匹配scream
,因为撇号没有字符。
不匹配suncreams
,因为末尾的 s 下落不明。
我没有很好地编程它,因为它只匹配所有单词。
我试过了。这很尴尬。我不知道我在做什么。
find = "s'cream"
with open('words') as f:
for line in f:
word = line.strip()
skipchars = False
for c in find:
if c == "'":
skipchars = True
continue
if skipchars:
for w in word:
if c != w:
continue
if c not in word:
break
skipchars = False
print(word)