def set_node_attributes(G, name, values):
    # Treat `value` as the attribute value for each node.
    if not isinstance(values, dict):
        values = dict(zip_longest(G, [], fillvalue=values))

    for node, value in values.items():
        G.node[node][name] = value
Sets node attributes from a given value or dictionary of values.
dataset/ETHPy150Open networkx/networkx/networkx/classes/function.py/set_node_attributes