import itertools
from collections import defaultdict
words = ['abc', 'def', 'adf', 'adc', 'acf', 'dec']
bigrams = {k: {''.join(x) for x in itertools.permutations(k, 2)} for k in words
    }
result = defaultdict(list)
for k, v in bigrams.items():
    for word in words:
        if k == word:
            continue
if len(bigrams[k] & bigrams[word]):
    result[k].append(word)
print(result)
BFS, wanting to find the longest path between nodes, reducing the findchildren-method