Re: why I get error for these function?

16 views
Skip to first unread message
Message has been deleted

Andrew

unread,
Jan 9, 2014, 3:18:15 AM1/9/14
to sage-s...@googlegroups.com
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? 
Reply all
Reply to author
Forward
0 new messages