get list in python
<pre><code>#ideal nodes list should be
['A','B','C','D','E','F','G','H','I','J','K','L','M','N']
</code></pre>

<p>So I tried to write a definition to read the nodes and edges.Here is my code,but it seems does not work.</p>

<pre><code>""" read nodes"""
def rd_nodes(a):
    nline =[line.split(":")[1].replace(';',',').split(',') for line in a]
    for i in nline:
        return i
</code></pre>

<p><a href="https://docs.python.org/3/library/itertools.html#itertools.combinations" rel="nofollow"><code>itertools.combinations</code></a> can help you here.</p>

<p>Try this:</p>

<pre><code>from itertools import combinations

s = """
1:A,B,C,D;E,F
2:G,H;J,K
&amp;:L,M,N
"""

nodes = set()
edges = set()

for line in s.split():
    clusters = line.split(':')[1].split(';')
    for cluster in clusters:
        _nodes = cluster.split(',')
        nodes.update(_nodes)
        edges.update(combinations(_nodes, 2))
</code></pre>

<p>You may use <a href="https://docs.python.org/3/library/collections.html#collections.OrderedDict" rel="nofollow"><code>collections.OrderedDict</code></a> structure for <code>nodes</code> and <code>edges</code> to maintain order if you want. Just use nodes and edges as dict keys and then at the end of the script get list of the keys.</p>

python list edges