def manhattan(rating1, rating2):
 distance = 0
 total = 0
 for key in rating1:
  if (key in rating2):
   distance += abs((rating1[key] - rating2[key]))
   total += 1
 if (total > 0):
  return (distance / total)
 else:
  return (-1)

def manhattan ( rating1 , rating2 ) : distance = 0 total = 0 for key in rating1 : if ( key in rating2 ) : distance += abs ( ( rating1 [ key ] - rating2 [ key ] ) ) total += 1 if ( total > 0 ) : return ( distance / total ) else : return ( - 1 )
computes the manhattan distance .