Lines 9
flatten (1)
Permissions
Owner: Stou S.
Viewable by Everyone
Editable by All Siafoo Users
Don't get spied on – We respect your privacy and provide numerous options to protect it.

Flatten list / tuple 0

 In Brief Apparently Python doesn't have a builtin flatten method... (yes you have the right to be annoyed!). Here's a simple recursive method to do the job. It will turn this ((1, 2), (3, 4), (5, 6)) into (1, 2, 3, 4, 5, 6)... more
 Language Python
# 's
` 1def flatten(lst): 2 3    res = [] 4     5    for l in lst: 6        if isinstance(l, list) or isinstance(l, tuple): 7            res.extend(flatten(l)) 8        else: 9            res.append(l)1011    return res`

Apparently Python doesn't have a builtin flatten method... (yes you have the right to be annoyed!). Here's a simple recursive method to do the job. It will turn this ((1, 2), (3, 4), (5, 6)) into (1, 2, 3, 4, 5, 6)

This method won't be able to handle deeply nested lists well but it works well for lists of coordinate tuples ((x,y,z)... )