I want to assign items of a list to the nodes of a graph one by one as attributes of those nodes. The code is as follows but it doesn't loop through the second "for". How can I fix this?
r = bernoulli.rvs(p=0.4, size=100)
G = nx.Graph(nx.powerlaw_cluster_graph(101, 1, 0.001))
nx.set_node_attributes(G, pol, 'politic')
r_list=r.tolist()
for i in G.nodes():
for elem in r_list:
G.nodes[i]['politic'] = elem
So if I get you right, I think you should do this
for i in G.nodes():
for elem in r_list[:]:
G.nodes[i]['politic'] = elem
r_list.remove(elem)
continue