import collections


def group_locations_by(locations, attribute):
    """
    Group locations into a dictionary of lists based on an attribute.

    :param list locations: A list of locations.
    :param str attribute: Attribute name.
    """
    grouped = collections.defaultdict(list)
    for location in locations:
        value = getattr(location, attribute)
        grouped[value].append(location)
    return grouped