i am having a text file which contain some text file like below.
file.txt
leptop
pencil
group
leptop
book
gruop
buk
grop
laftop
pensil
laptop
pancil
laptop bag
bok
from that file i need to find out the related query and store in to a list like below.
[leptop,leptop,laftop,laptop]
[pencil,pensil,pancil]
[group,gruop,grop]
[book,buk,bok]
[laptop bag]
i found something like below.it's working pretty well . but i want some modification on this.
import keyword
from difflib import get_close_matches
lis = ["leptop","pencil","group","leptop","book","gruop","bowk","grop","laftop","pensil","laptop","pancil","laptop bag","bok"]
print get_close_matches("laptop",lis, n = len(lis))
print get_close_matches("pencil", lis, n = len(lis))
print get_close_matches("group", lis, n = len(lis))
print get_close_matches("book", lis, n = len(lis))
output:-
['laptop', 'leptop', 'leptop', 'laftop', 'laptop bag'] # i don't want "laptop bag" as output over here.
['pencil', 'pensil', 'pancil']
['group', 'grop', 'gruop']
['book', 'bok', 'bowk']