Forked from fish2000/almost-ascii-deletion-distance.py
Created
September 19, 2018 01:20
-
-
Save AppMkrATL/52b02e9f2486a0c9aa45968b22797b80 to your computer and use it in GitHub Desktop.
Revisions
-
fish2000 created this gist
Mar 14, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ def ascii_deletion_distance(str1, str2): from collections import defaultdict histogram = defaultdict(int) for ch in str1: histogram[ch] += 1 for ch in str2: histogram[ch] += 1 union = set(str1) | set(str2) intersection = set(str1) & set(str2) result = union - intersection # values = [ord(ch) for ch in result] out = 0 for ch in result: out += (histogram[ch] * ord(ch)) return out