I'm new to Python and got stuck while implementing an algorithm for drawing graphs. I have a list of tuples that contain certain nodes and their 'level' (for layering). Initially that looks like this:
[(0, 10), (1, 'empty'), (2, 'empty'), (3, 'empty'), (4, 'empty'), (5, 'empty'), (6, 'empty'), (7, 'empty'), (8, 'empty'), (9, 'empty')] (node,level)
Now I need to assign levels to these nodes as long as any node has no level, respective the 'empty' attribute.
I tried several structures of possible while conditions, that syntactically weren't wrong but semantically didn't make any sense, since the while loop didn't terminate:
while (True for node, level in g.nodes(data='level') if level == 'empty'):
or
while ( 'empty' in enumerate(g.nodes(data='level') ):
and certain other similar constructs, that didn't work and I don't remember..
Until now it doesn't seem clear to me why this won't work - python didn't even enter the while loop with these conditions. Can you explain me why and hand me a clue how to fix it?
hint: g.nodes(data='level') is a networkx function, that returns the upper list of tuples