Access to networkx nodes and attributes

I have this GraphML file that I read in Networkx.

So, I refer to all the nodes:

g.nodes() 

He gives me a list of strings. Let's say one of them is 123. Then I try to access node as:

 g["123"] 

and he gives me a dictionary.

Then I try to access the nodes using the nodes function as follows:

 for n in g.nodes( data = True ): print n 

Then it gives me a 2-tuple with the string node name as the first element and the dictionary as the second element.

The fact is that this is an excellent dictionary from the first. And this is confusing for me, so any help here is appreciated.

Should they be different? If so, why? If not, what am I doing wrong? :) I can post actual data if that helps.

+4
source share
1 answer

Have you looked at various pages of documentation

nlist : list

List of nodes. If data = True, a list of two tuples containing (node, node data dictionary).

and...

adj_dict : dictionary

An adjacency dictionary for nodes associated with n.

"Node data dictionary" and "adjacendy dictionary" are not the same thing.

+6
source

Source: https://habr.com/ru/post/1400708/


All Articles