> [[1],[2,8,4,6],[1,2,7],[9,3,4,6],...]
> [[1],[14,17,18,19],[1,4,11],[9,14,16,19],...]
>
> would like to figure out how to get both results like this:
>
> [1,2,8,4,6,1,2,7,9,3,4,6,...]
> [1,14,17,18,19,1,4,11,9,14,16,19...]

Two ways come to mind:

sage: a = [[1],[2,3,4],[5,6,7]]
sage: a
[[1], [2, 3, 4], [5, 6, 7]]
sage: flatten(a)
[1, 2, 3, 4, 5, 6, 7]
sage: sum(a,[])
[1, 2, 3, 4, 5, 6, 7]

The two approaches differ in how deep they go: flatten recurses
downwards whereas the sum only goes down one level.  Sometimes you
want one or the other:

sage: b = [[1],[[2,3],[4,5]]]
sage: b
[[1], [[2, 3], [4, 5]]]
sage: flatten(b)
[1, 2, 3, 4, 5]
sage: sum(b,[])
[1, [2, 3], [4, 5]]


Doug

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to