def nestedmap(f, args, type=list):
    """
    Map `f` over `args`, which contains elements or nested lists
    """
    result = []
    for arg in args:
        if isinstance(arg, type):
            result.append(list(map(f, arg)))
        else:
            result.append(f(arg))

    return result