我正在尝试使用循环将地址x与地址匹配并遍历字符串中的单词,一次删除一个,直到找到匹配项。我正在展示一个ywhilesplit()type error
我想知道是否有人可以帮助我正确地使用这个过程来循环单词?
x = 'Shop 9 Corner Cramer and Mary Street, Preston'
y = 'Corner Cramer and Mary Street, Preston'
def cut2(address):
while address != y:
p = address.split((" ",0)[0])
p = p + 1
print(f"Address Check {address}")
else:
print(address)
我想要的输出是:
Corner Cramer and Mary Street, Preston
我得到的输出是:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-4-a8e028e05091> in <module>
----> 1 cut2(x)
<ipython-input-3-342a77a7d0bd> in cut2(address)
5 while address != y:
6 p = address.split((" ",0)[0])
----> 7 p = p + 1
8
9 print(f"Address Check {address}")
TypeError: can only concatenate list (not "int") to list