Awesome. Thanks all !!

On Jul 23, 10:11 am, Mike Hansen <mhan...@gmail.com> wrote:
> On Thu, Jul 22, 2010 at 10:04 PM, vasu <tewari.v...@gmail.com> wrote:
> > I am iterating through all partitions p  of a fixed length k ( let's
> > say using Partitions (size, length=k) ) and I have written a function
> > which return true if the partition p has atleast one part repeated. I
> > can use a for loop and get the thing done easily.
> > But is there a way I can use filter() to achieve the same purpose ?
> > I hope my question is clear.
>
> You can also do something like the following which is specific to the
> type of object that Partitions() returns:
>
> sage: P = Partitions(10,length=3).filter(lambda p: 3 in p); P
> Filtered sublass of Partitions of the integer 10 satisfying constraints 
> length=3
> sage: list(P)
> [[6, 3, 1], [5, 3, 2], [4, 3, 3]]
> sage: P.cardinality()
> 3
>
> --Mike

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

Reply via email to