Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Determine the Order by Moff
def checkio(a):
edges = []
for w in a:
edges.append(('_', w[0]))
for i in range(1, len(w)):
if w[i-1] != w[i]:
edges.append((w[i-1], w[i]))
result = ''
s = set()
for a, b in edges:
s.add(a)
for a, b in edges:
if b in s:
s.remove(b)
s = list(s)
while s:
s.sort()
c = s.pop(0)
result += c
for edge in [e for e in edges if e[0] == c]:
m = edge[1]
edges.remove(edge)
if not [1 for x, y in edges[:] if y == m]:
s.append(m)
return result[1:]
Aug. 24, 2015