graph = {'a': ['a'], 'b': ['d'], 'c': ['f'], 'd': [], 'e': ['f'], 'f': [],
    'g': [], 'm': ['g'], 'n': ['f']}
print([vertex for vertex, edges in list(graph.items()) if 'f' in edges])
Представление сети в Python