1import networkx
2
3G1 = networkx.Graph()
4G1.add_edges_from([('a','b'),('b','c'),('c','e'),('c','d'),('c','f'),('c','g')])
5to_be_removed = [x for x in G1.nodes() if G1.degree(x) <= 1]
6
7for x in to_be_removed:
8 G1.remove_node(x)
9
10print(G1.edges())