Just change
if (C in Subsets(G.neighbors(1))):
to
if (x!=y and C in Subsets(G.neighbors(1))):
It's probably more efficient to write something like:
N=Set(G.neighbors(1))
NN={x for x in G.neighbors(y) for y in N} # neighbours of neighbours of 1
NN={x for x in NN if Set(G.neighbors(x)).issubset(N)} # subset of NN with
neighbours contained in N
print [(x,y) for (x,y) in CartesianProduct(NN,NN) if x!=y]
Andrew
On Thursday, 9 January 2014 08:27:25 UTC+1, Neda wrote:
>
> Hello, I want to compute this:
>
> G= graphs.CompleteGraph(4)
> G.delete_edge({1,2})
> L = [u for u in G.vertices()]
> for x in L:
> for y in L:
> A = Set(G.neighbors(x))
> B = Set(G.neighbors(y))
> C= A.union(B)
> if (C in Subsets(G.neighbors(1))):
> print(x,y)
> the result is :
>
> (1, 1)
> (1, 2)
> (2, 1)
> (2, 2)
>
>
> but I don't want the function prints (1,1) & (2,2)
>
> so what should I write in the function to omit these pairs?
>
>
--
You received this message because you are subscribed to the Google Groups
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/groups/opt_out.