igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] add vertex and set its attribute


From: Tamas Nepusz
Subject: Re: [igraph] add vertex and set its attribute
Date: Tue, 18 Jan 2011 14:12:22 +0100

> Is there a single line  code I can use for this or should I recover the 
> vertex by its id, which I suppose will be the larger in the graph?
THe ID of the newly added vertex should  be the largest in the graph,
so you can use that. Alternatively, you can create a helper method:

def add_vertex_with_attrs(graph, attrs):
    n = graph.vcount()
    graph.add_vertices(1)
    for key, value in attrs.iteritems():
        graph.vs[n][key] = value

Then you can simply call:

add_vertex_with_attrs(graph, {"type": 0})

-- 
Tamas



reply via email to

[Prev in Thread] Current Thread [Next in Thread]