def flatten(l):
    """Flatten a nested list to a one dimensional list."""
    r = []
    for item in l:
        if isinstance(item, list) or isinstance(item, tuple):
            r.extend(flatten(item))
        else: r.append(item)
    return r