def extract_node_attribute(graph, name, default=None):
    """
    Extract attributes of a networx graph nodes to a dict.
    :param graph: target graph
    :param name: name of the attribute
    :param default: default value (used if node doesn't have the specified attribute)
    :return: a dict of attributes in form of { node_name : attribute }
    """
    return { i : d.get(name, default) for i, d in graph.nodes(data=True) }