是否可以检查列表元素?如果它与“test01.txt”中的单词相同,则替换为空格?
测试01.txt:
to
her
too
a
for
在代码中:
with open('C:/test01.txt') as words:
ws = words.read().splitlines()
with open('C:/test02.txt') as file_modify4:
for x in file_modify4:
sx = map(str.strip, x.split("\t"))
ssx = sx[0].split(" ")
print ssx
“打印 ssx”的结果:
['wow']
['listens', 'to', 'her', 'music']
['too', 'good']
['a', 'film', 'for', 'stunt', 'scheduling', 'i', 'think']
['really', 'enjoyed']
如何替换ssx中的元素?
预期结果:
['wow']
['listens', ' ', ' ', 'music']
[' ', 'good']
[' ', 'film', ' ', 'stunt', 'scheduling', 'i', 'think']
['really', 'enjoyed']
有什么建议吗?