Ask Your Question

'method' object is not subscriptable

asked 2020-11-30 10:16:09 +0200

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):
    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!

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2020-11-30 11:20:51 +0200

FrédéricC gravatar image

updated 2020-11-30 11:21:33 +0200

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

edit flag offensive delete link more

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


Asked: 2020-11-30 10:16:09 +0200

Seen: 93 times

Last updated: Nov 30 '20