Mercurial > hg > python
view req_dep.py @ 31:1252f8100c6a
printouts to aid further testing
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Thu, 29 Jul 2021 12:44:00 +0100 |
parents | e07789816ca5 |
children |
line wrap: on
line source
#!/usr/bin/python2.7 import sys kids={} parents={} known=set(()) l=sys.stdin.readline() while l: ff=l.strip().split() if len(ff)!=0: d=ff[0] sys.stdin.readline() pp=sys.stdin.readline().strip().replace(',','').split()[2:] parents[d]=pp known.add(d) for p in pp: known.add(p) try: c=kids[p] c.add(d) except KeyError: c=set([d]) kids[p]=c l=sys.stdin.readline() roots={} still=set(()) for k in known: if k in parents: still.add(k) else: roots[k]=set([k]) #print len(parents),len(kids),len(roots),len(still),roots print roots.keys() while len(still)>0: #print len(still),len(roots) pend=still still=set([]) while len(pend)>0: x=pend.pop() #print x,len(pend) for p in parents[x]: try: r=roots[p] roots[x]=roots.get(x,set(())).union(r) except KeyError: if p in parents: still.add(x) for x,r in sorted(roots.items()): print x,r