def get_maxprofits(legs, classes):
    """Loops through each leg and gets the maximum profit of that leg

    The max profit is added as key to the legs dictionary

    Parameters
    ----------
    legs : list of dictionaries
        List of dictionaries, where each dictionary represents a leg
    classes : dictionary
        Dictionary that will contain the existing airplane classes

    Returns
    -------
    legs : list of dictionaries
        Same list as input, but each leg now has a key named maxprofit with the corresponding max profit
    """

    if legs:
        classes = list(classes.keys())

        for leg in legs:
            profits = [leg[c] for c in classes]
            leg['maxprofit'] = max(profits)

    return legs