I have a networkx graph. I am adding nodes by adding edges
G.add_edge(route[i-1],route[i]);
Now once the node is created by directly adding edges, I add a list named
G.node[route[i]]['position'] = list()
and I append positions to it when I get same nodes again and again
G.node[route[i]]['position'].append( i - 3 )
Now when I want to append how do I check whether the list exist? does doing
G.node[route[i]]['position'] = list()
clear the list of already existing elements?
edit----- my earlier question was confusing
I want to keep adding to the list
but I cant append unless a list exists, right?
So I have to do do
G.node[route[i]]['position'] = list()
in my loop
So next time when I want to add to the same list in another loop instance how do I know that a list exists for G.node[route[i]]['position']
and I dont have to create it again.
edit----- I think my list itself is a key here so I did
if not 'position' in G.node[route[i]]:
and it works