def flatten(chain):
    """
    Take input from get_option_chain()
    and flatten so that each contract is on its own.
    Can then be sorted easily with comprehensions for example.
    """

    flattened = []
    for key in ["callExpDateMap", "putExpDateMap"]:
        for date in chain[key]:
            for strike in chain[key][date]:
                for contract in chain[key][date][strike]:
                    flattened.append(contract)

    return flattened