Reputation: 75
What I want to do is take names from namelist, compare those to names in banklist, and if there is an item in banklist which looks a lot like an item in namelist, I want to append that item to a closematchlist. The goal of this is to find items that occur in both lists, even if there is a spelling error in namelist. When I print(closematch), it works like intended: the close matches in banklist get found and printed. However, when I try to append those items to a list, the result of print(closematchlist) is [].
for name in namelist:
closematch = difflib.get_close_matches(name, banklist, 1, 0.8)
closematchlist = list()
closematchlist.append(closematch)
print(closematch)
print(closematchlist)```
Upvotes: 0
Views: 140
Reputation: 172367
difflib.get_close_matches()
is a list of close matches. You don't need to copy it to a new list.
Upvotes: 3