我以为我正在理解 python 中的拆分和连接,但它不适合我。
让我们说的价值inp[17] = 'Potters Portland Oregon school of magic'
# a string of data I am pulling from a csv file, the data comes through just fine.
loc = inp[17]
l = loc.split(' ') # I want to split by the space
# I want to filter out all these words say they don't always
# come as "School of magic" so I cant just filter that out they
# could be mixed around at times.
locfilter = ['Potters', 'School', 'of', 'magic']
locname = ' '.join([value for value in l if l not in locfilter])
此时我的locname
变量应该只包含Portland Oregon
在其中,但它仍然'Potters Portland Oregon school of magic'
没有过滤掉。
我做错了什么我认为问题出在我的locname =
线上。
谢谢你的帮助。