![](/img/trans.png)
[英]Python - Append items to a list while making https requests inside a loop
[英]How do I append items to a list inside a for loop in python?
我想要做的是從名單中取名字,將它們與銀行列表中的名稱進行比較,如果銀行列表中有一個項目看起來很像名單中的項目,我想將該項目 append 到 closematchlist。 這樣做的目的是查找出現在兩個列表中的項目,即使名稱列表中存在拼寫錯誤。 當我打印(closematch)時,它按預期工作:找到並打印banklist中的密切匹配。 但是,當我嘗試將 append 這些項目添加到列表時,print(closematchlist) 的結果是 []。
for name in namelist:
closematch = difflib.get_close_matches(name, banklist, 1, 0.8)
closematchlist = list()
closematchlist.append(closematch)
print(closematch)
print(closematchlist)```
difflib.get_close_matches()
是緊密匹配的列表。 您無需將其復制到新列表中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.