Skip to main content
`Ctrl`+`K`

# get_node_attributes

get_node_attributes(G, name, default=None)

  Get node attributes from graph

  Parameters:
    G NetworkX Graph
    name string

      Attribute name

    default: object (default=None)

      Default value of the node attribute if there is no value set for that node in graph. If `None` then nodes without this attribute are not included in the returned dict.

  Returns:
    Dictionary of attributes keyed by node.

  Examples

      >>> G = nx.Graph()
      >>> G.add_nodes_from([1, 2, 3], color="red")
      >>> color = nx.get_node_attributes(G, "color")
      >>> color[1]
      'red'
      >>> G.add_node(4)
      >>> color = nx.get_node_attributes(G, "color", default="yellow")
      >>> color[4]
      'yellow'