import networkx as nx import matplotlib.pyplot as plt import re floppy = open("input25.txt", mode='r', encoding='utf-8') thing = floppy.readlines() floppy.close() sourcenode = [] for i, word in enumerate(thing): sourcenode.append(word[0:3]) thing[i] = word[4:].split() visual = [] for i, source in enumerate(sourcenode): for dest in thing[i]: visual.append([source,dest]) G = nx.Graph() G.add_edges_from(visual) nx.draw_networkx(G) plt.show()
import networkx as nx import matplotlib.pyplot as plt G = nx.Graph() G.add_edges_from([['a','b'],['b','c'],['a','c'],['s','u']]) nx.draw_networkx(G) plt.show()