我有以下的字典,
d={'City':['Paris', 'Berlin','Rome', 'London']}
和下面的一個元素的列表,
address=['Bedford Road, London NW7']
問題
我想檢查一個城市是否在地址中。
嘗試到目前爲止
(1)
for x in d['City']:
if x in address:
print('yes')
else:
print('no')
只打印no
。
(2)
for x in d['City']:
r = re.compile(x)
newlist = list(filter(r.match, address))
給出TypeError: 'str' object is not callable
。從this answer得到這個似乎是應該解決這個問題,但錯誤沒有幫助。
我該怎麼辦?
謝謝。就是這樣。切換到你光滑的替代雖然;) – LucSpan