from collections import defaultdict
segments = [['Ntv', 'Tbh'],
['Vyt', 'Tbh'],
['Roh', 'Vyt'],
['Roh', 'Ntv'],
['Vyt', 'Ntv']]
neighbours = defaultdict(set)
for ab in segments:
neighbours[min(ab)].add(max(ab))
aa = list(neighbours.keys())
for a in aa:
for b in neighbours[a]:
for c in neighbours[a] & neighbours[b]:
print(a, b, c)
Ntv Tbh Vyt
Ntv Roh Vyt
def f()
return {"a" => 1};
end
result = nil
p(result) if (result = f()).is_a?(Hash) # {"a"=>1}