Whats the best way to iterate though a list in python that contains ordered pairs, by a certain value in another list. For example
T=({6},[(3,5), (5,6)])
incidental_edges=[(3,6),(4,6),(5,6)]
I have tried many different ways to prevent cycling for example:
def valid_edges(T,G)
edges=[]
for v in T[0]
for e in incident_edges(T,G):
if v in e:
edges.append(e)
for x in T[1]:
for u in x:
if u in edges:
edges.remove(x)
my expected output is:
[4,6]
Also i understand that using a 2d array would make this easier but I have to use the tree as seen above.
G is a txt file that has columns with u v d, and T[0] can appear in either u v. edges are compromised of (u,v)
TDLR; im trying to prevent cycling and im a noob. Thanks for the help in advance.