Skip to content

Instantly share code, notes, and snippets.

@landonsanders
Created June 5, 2014 13:28
Show Gist options
  • Select an option

  • Save landonsanders/d194ccaf23529c49091f to your computer and use it in GitHub Desktop.

Select an option

Save landonsanders/d194ccaf23529c49091f to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment