Ask Your Question
1

'method' object is not subscriptable

asked 4 years ago

Ingrid gravatar image

Starting with a graph G, I would like to make a list, the ith element of which is the graph G with its ith edge deleted.

def graphlist(G):
    n=len(G.edges())
    L=[G.copy().delete_edge(G.edges[i][0], G.edges[i][1]) for i in range(n)]
    return L

When I enter the definition above, or a variation of it, I get the error

'method' object is not subscriptable

Thanks a lot for any suggestions!

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 4 years ago

FrédéricC gravatar image

updated 4 years ago

G.edges is a method, use list(G.edges()) for the list of edges. Store this in a variable before the loop.

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 4 years ago

Seen: 757 times

Last updated: Nov 30 '20