d ='''A -> B
A -> C
B -> C
B -> D
C -> D
D -> C
E -> F
F -> C'''
e = [i.strip() for i in d.split('\n')]
v = set()
for i in e:
for j in i:
if j>='A':
v.add(j)
v = list(v)
v.sort()
print(e)
print(v)
g = {}
for i in v:
t = []
for j in e:
if i in j:
for k in j:
if k>='A' and k<='Z':
if k not in i:
t.append(k)
g[i]=t
print(g)
沒有留言:
張貼留言