0

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.

ChanMan
  • 11
  • 3
  • 1
    Can you clarify what are you trying to achieve? – Newskooler Dec 11 '18 at 04:51
  • @newskooler basically trying to take edges in incident_edges and make sure none of the pairs of vertices are in T[1]. I believe this would prevent cycling. 6, the value in T[0] is the vertices I’m currently at, so incident_edges is pulling in all pairs from from a file that has a 6 in it. – ChanMan Dec 11 '18 at 05:02

0 Answers0