Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save AppMkrATL/52b02e9f2486a0c9aa45968b22797b80 to your computer and use it in GitHub Desktop.

Select an option

Save AppMkrATL/52b02e9f2486a0c9aa45968b22797b80 to your computer and use it in GitHub Desktop.

Revisions

  1. @fish2000 fish2000 created this gist Mar 14, 2017.
    15 changes: 15 additions & 0 deletions almost-ascii-deletion-distance.py
    Original 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