import six


def get_comparable_revisits(query_metadata_table):
    """Return a dict location -> set of revisit locations for that starting location."""
    revisit_origins = {
        query_metadata_table.get_revisit_origin(location)
        for location, _ in query_metadata_table.registered_locations
    }

    intermediate_result = {
        location: set(query_metadata_table.get_all_revisits(location))
        for location in revisit_origins
    }

    return {
        location: revisits
        for location, revisits in six.iteritems(intermediate_result)
        if revisits
    }