def compose(*funcs):
    """Return a new function s.t.
       compose(f,g,...)(x) == f(g(...(x)))"""
    def inner(*args):
        result = args
        for f in reversed(funcs):
            if type(result) in (list, tuple):
                result = f(*result)
            else:
                result = f(result)
        return result
    return inner