Created
June 5, 2014 13:28
-
-
Save landonsanders/d194ccaf23529c49091f to your computer and use it in GitHub Desktop.
Compute the Manhattan Distance between two points in a space
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 characters
| 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