On Feb 10, 10:31 am, green351 <[email protected]> wrote:
> Hi.  I have the following problem: consider the following list of
> compositions and its cartesian product with itself.
>
> C83=Compositions(8, length=3);
> cp=CartesianProduct(C83,C83)
>
> I want to remove certain elements from this set/list and then to count
> the elements left.  For example I want to remove the element [[1,1,6],
> [1,2,5]] and in general for [[a,b,c],[d,e,f]], I want to remove it if
> a=d=1 OR b=e=1 Or c=f=1.  There are other things I want to remove but
> I think if I figure out the correct syntax for the above I could
> probably figure the rest out. How would I do this?

One way is to use "filter":

Y = cp.filter(lambda x: x[0][0] != 1 or x[1][0] != 1)

keeps pairs x=[[a,b,c], [d,e,f]] so that either a != 1 or d != 1, so
you could do something like

Y = cp.filter(lambda x: (x[0][0] != 1 or x[1][0] != 1) and (x[0][1] !=
1 or x[1][1] != 1) and
                        (x[0][2] != 1 or x[1][2] != 1))

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to