On 10/26/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > which produces a nested list. Is there a way to flatten the list by one > > or two levels, but not flatten it all the way? Something like: > > > > sage: flatten([[[1,2],[3,4]],[[5,6],[7,8]]],1) > > [[1,2],[3,4],[5,6],[7,8]]
An easy way to do the above is the following: sage: v = [[[1,2],[3,4]],[[5,6],[7,8]]] sage: sum(v, []) [[1, 2], [3, 4], [5, 6], [7, 8]] sage: sum(sum(v, []), []) [1, 2, 3, 4, 5, 6, 7, 8] This is not a flatten-to-level 1 in general, but if you really want to do just things like the example above it does what you want. William --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~----------~----~----~----~------~----~------~--~---