I have this sample code for python Counter.
from collections import Counter
lst = ['item', 'itemm', 'iitem', 'foo', 'bar']
c = Counter(lst)
Counter({'bar': 1, 'foo': 1, 'iitem': 1, 'item': 1, 'itemm': 1})
If I do c['item']
I get 1
, but I want to get 3
due to the typos in the list.
I tried the following, it doesn't give me 3
but I still work with it:
import re
for word in lst:
if re.search('item',word):
print(word,c[word])
item 1
itemm 1
iitem 1
Is there a more efficent way to do it without looping through list?