def flatmap(fn, seq):
    """
    Map the fn to each element of seq and append the results of the
    sublists to a resulting list.
    """
    result = []
    for lst in map(fn, seq):
        for elt in lst:
            result.append(elt)
    return result