【发布时间】:2021-03-05 14:13:51
【问题描述】:
我有两个字符串列表:
grids = ['north', 'eaSt', 'West','noRtheast', 'soUth']
links = ['north-northeast', 'north-south']
我想检查grids 在links 中的内容。所以我为此写了一个程序:
import re
grids = ['north', 'eaSt', 'West','noRtheast', 'soUth']
links = ['north-northeast', 'north-south']
for search in grids:
for text in links:
result = re.findall('\\b' + search + '\\b', text, flags=re.IGNORECASE)
print(result)
输出:
['north']
['north']
[]
[]
[]
[]
['northeast']
[]
[]
['south']
我几乎得到了输出,但不明白为什么我会在输出中得到那些空白,所以我可以为这个获得更简单和干净的替代方案吗?
【问题讨论】: