Or, (to add needed recursion to your simple loop):

def flatten(x):
    "Modified in-place flattening"
    for i in range(len(x)):
        if isinstance(x[i], list):
            x[i:i+1] = flatten(x[i])
    return x

This version modifies in-place (as yours does), which may or may not be
what you want, depending on whether or not you need both the flat and
un-flat versions.

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to