flatten nested list

def flatten(x):
    if isinstance(x, list):
        return [a for i in x for a in flatten(i)]
        return [x]

Here is what the above code is Doing:
1. If x is a list, iterate over it and recursively call flatten on each element.
2. If x is not a list, return a list with x as its only element.
3. In the end, we use a list comprehension to concatenate all the lists together.