user2535338
user2535338

Reputation: 385

Trouble with Igraph library

I'm trying to use igraph in python 3 :

g.vs["name"] = ["Alice", "Bob", "Claire", "Dennis", "Esther", "Frank", "George"]

the anwser should be

 g.vs["name"]
 ["Alice", "Bob", "Claire", "Dennis", "Esther", "Frank", "George"]

but the answer I've got is :

g.vs["name"]
[]

Whats wrong?

Upvotes: 1

Views: 43

Answers (1)

Paul Brodersen
Paul Brodersen

Reputation: 13041

Despite appearances, igraph.Graph.vs is not a dictionary (where your assignment would be expected to work) but of type igraph.VertexSeq. Unlike a dictionary, igraph.Graph.vs[some_attribute] only allows you to get the data, not to set the data. To add nodes with the indicated names. do the following:

import igraph

g = igraph.Graph()
g.add_vertices(["Alice", "Bob", "Claire", "Dennis", "Esther", "Frank", "George"])
print g.vs['name']
# ["Alice", "Bob", "Claire", "Dennis", "Esther", "Frank", "George"]

Upvotes: 1

Related Questions