> P.S. On a different note, my real code has something like:
>
> sage: [solve([eq1,eq2,eq3,p==i],p,q,x,y) for i in [1..4]]
>
> 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]]


There's a "nice" pythonic way to do that for a fixed level:

def flatten_one(l):
    return [v  for li in l  for v in li]

def flatten_two(l):
    return [v  for li in l  for lii in li  for v in lii]

and an absolutely horrendous way to do it for a variable number of levels, 
which involves the construction and evaluation of a generalization of the 
above.  (or... one could do it recursively)

def flatten_n(l,n):
     if n < 1:
         return l
     else:
         l = flatten_one(l)
         if n == 1:
             return l
         else:
             flatten_n(l,n-1)


--~--~---------~--~----~------------~-------~--~----~
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/
-~----------~----~----~----~------~----~------~--~---

Reply via email to