How can I tell difflib.get_close_matches () to ignore case? I have a dictionary that has a specific format that includes capitalization. However, the test line may have full capitalization or lack of capitalization, and they should be equivalent. However, the results should be correctly capitalized, so I cannot use a modified dictionary.
import difflib names = ['Acacia koa A.Gray var. latifolia (Benth.) H.St.John', 'Acacia koa A.Gray var. waianaeensis H.St.John', 'Acacia koaia Hillebr.', 'Acacia kochii W.Fitzg. ex Ewart & Jean White', 'Acacia kochii W.Fitzg.'] s = 'Acacia kochi W.Fitzg.'
Conclusion:
['Acacia kochii W.Fitzg.'] [] []
Work code:
Based on Hugh Botwell's answer, I changed the code as follows to get a working solution (which should also work when more than one result is returned):
import difflib names = ['Acacia koa A.Gray var. latifolia (Benth.) H.St.John', 'Acacia koa A.Gray var. waianaeensis H.St.John', 'Acacia koaia Hillebr.', 'Acacia kochii W.Fitzg. ex Ewart & Jean White', 'Acacia kochii W.Fitzg.'] test = {n.lower():n for n in names} s1 = 'Acacia kochi W.Fitzg.'
Conclusion:
['Acacia kochii W.Fitzg.', 'Acacia kochii W.Fitzg.']
source share