Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from functools import reduce
- g = {1:{2,3,4}, 2:{1,3}, 3:{1,4}, 4:{1,3}}
- def transf(graph, f):
- def reducer(acc, elem):
- aux = set(map(f, elem))
- elem.clear()
- elem.update(aux)
- reduce(reducer, graph.values(), None)
- return graph
- print(transf(g, lambda x: x ** 2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement