【发布时间】:2020-02-24 15:38:01
【问题描述】:
所以,我是 Python 新手。如果我的列表的值也在另一个列表中,我想替换它们并将它们更改为指定的值,伪令牌(OOV)。我已经将它们变成了令牌,并使用正则表达式稍微清理了代码。 这是我的代码:
def replace_words(list1, list2):
for word in list1:
for words in list2:
if word == words:
word = "OOV"
replace_words(list1, list2)
list1.count("OOV") #this keeps showing 0, so something is wrong...
【问题讨论】:
-
你的list1和list2是什么?
-
如果有示例输入能够实际重现这一点,将会有很大帮助。