def stations_by_river(stations):
    """Creates a dictionary, using river names as keys to station objects on that river. Used in Task1D.py
    
    Args: stations (list of MonitoringStation objects)
    
    Returns: river_dict (dictionary with river names as keys to station objects"""

    # Create an empty dictionary
    river_dict = {}

    # If river already in the dictionary, add the station object to a list under that key
    for item in stations:
        if item.river in river_dict:
            river_dict[item.river].append(item)

    # If river not in dictionary, add a new entry with river as key and station object mapped by it
        else:
            river_dict[item.river] = [item]

    return river_dict