def locations_within(a, b, tolerance):
    ret = ''
    b = dict(b)
    for (key, value) in a.items():
        if key not in b:
            raise ValueError("b does not have the key: " + key)
        if abs(int(value) - int(b[key])) > tolerance:
            ret += 'key {0} differs: {1} {2}'.format(key, int(value),
                                                     int(b[key]))
        del b[key]
    if b:
        raise ValueError("keys in b not seen in a: " + ", ".join(b.keys()))
    return ret