python - Determining if string B could be the result of a deletion/addition to string A -
assume have base of operations string of length 29, , list of arbitrary strings of lengths 28 , 30. how determine number of these strings result of deletion/addition of 1 character performed on base of operations string?
i'm doing in python, record.
let's see... modify levenshtein distance algorithm (python code here) create work in case of add-on or deletion of 1 character.
from functools import partial my_distances import **add_delete_distance** def is_accepted(base_string, alternative_string): '''it uses custom distance algorithm evaluate (boolean output) if particular alternative string ok respect base of operations string.''' assert type(alternative_string) == str len_difference = abs(len(base_string)-len(alternative_string)) if len_difference == 1 : distance = add_delete_distance(base_string, alternative_string) if distance == 1: homecoming true homecoming false base_string = 'michele' alternative_strings = ['michel', 'michelle', 'james', 'michela'] print filter(partial(is_accepted, base_string), alternative_string)
what think it?
python string algorithm insertion
No comments:
Post a Comment