Skip to content

Instantly share code, notes, and snippets.

View landonsanders's full-sized avatar

Landon Sanders landonsanders

View GitHub Profile
@landonsanders
landonsanders / gist:d194ccaf23529c49091f
Created June 5, 2014 13:28
Compute the Manhattan Distance between two points in a space
def manhattan(rating1, rating2):
"""Computes the Manhattan distance. Both rating1 and rating2 are
dictionaries of the form
{'The Strokes': 3.0, 'Slightly Stoopid': 2.5 ..."""
distance = 0
for key in rating1:
if key in rating2:
distance += abs(rating1[key] - rating2[key])
return distance