Ask Your Question

'method' object is not subscriptable

asked 2020-11-30 03:16:09 -0600

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 04:20:51 -0600

FrédéricC gravatar image

updated 2020-11-30 04:21:33 -0600

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 03:16:09 -0600

Seen: 52 times

Last updated: Nov 30 '20