On Thu, 22 Jul 2010 at 10:04PM -0700, vasu wrote:
> I am trying to use something like the filter() command, for this
> purpose mentioned below:
> 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.

In Python, you typically use list comprehensions:

[x for x in some_list if some_condition]

If your function is called has_repeated_part, you would use

[p for p in Partitions(n, length=k) if has_repeated_part(p)]


Dan

--
---  Dan Drake
-----  http://mathsci.kaist.ac.kr/~drake
-------

Attachment: signature.asc
Description: Digital signature

Reply via email to