python compute closeness of strings -
i want compare string representations of 3 or 4 digit integers. want group them pairs of 'closeness'. is, pc_dud[3]
should pair dud[0]
.
dud = ['3433', '3467', '3551', '345', '345', '3613'] pc_dud = ['3401', '3402', '3430', '0342', '3584']
does know of tool out there (i thinking myself maybe jellyfish)? solution of course use arithmetical difference indicator 'closeness'. thoughts?
you can use difflib module:
example:
>>> import difflib >>> dud = ['3433', '3467', '3551', '345', '345', '3613'] >>> pc_dud = ['3401', '3402', '3430', '0342', '3584'] >>> difflib.get_close_matches(dud[0], pc_dud) ['3430']
Comments
Post a Comment