Harald Schilly wrote:
> On Jan 24, 1:47 pm, "William Stein" <[EMAIL PROTECTED]> wrote:
>> Thanks.  I would actually strongly encourage you or somebody to
>> sit down and actually write a function that has the _same_ functionality
>> as http://reference.wolfram.com/mathematica/ref/Partition.html
> 
> Hi, i would also suggest to write similar functions for other type of
> list manipulation. like the "Flatten" function with different levels
> of depth as an opposite of partition.
> e.g.
> 
> sequence_flatten([[a,[b,c]],[d]],level=1)
> gives
> [a,[b,c],d] (or something like that)
> 
> maybe this is more important for the lisp based interface (partition,
> flatten, map, apply, cross, ...) for mathematica, but there are other
> uses, too.

A while ago I added a max_level argument to flatten that does at least 
some of this functionality.  For example:

sage: flatten([[a,[b,c]],[d]], max_level=1)
[a, [b, c], d]

It was kind of neat---the original flatten function was clever in how it 
avoided recursion, since Python isn't so great with recursion.  Do 
"flatten?" to see the docs, of course.

I agree that having more power in the flatten function would be nice. 
However, one problem is that Python doesn't have great support for a lot 
of the functional type of things (for example, I don't think tail 
recursion is implemented, so you run into recursion depth problems, and 
the support for functional idioms is only going to get "worse", if I 
understand the future of Python correctly).  On the bright side, list 
comprehensions replace a lot of the need and do it very nicely.

Python does have map and apply and filter, but it seems like their use 
is frowned upon in general in favor of list comprehensions; correct me 
if I'm wrong, though.

Jason


--~--~---------~--~----~------------~-------~--~----~
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://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to