Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import functools
- g = {1:{2,3,4}, 2:{1,3}, 3:{1,4}, 4:{1,3}}
- lst = [(2,4), (3,2)]
- def addToGraph(graph, lst):
- def reducer(acc, elem):
- graph[elem[0]].add(elem[1])
- #graph[elem[1]].add(elem[0])
- functools.reduce(reducer, lst, None)
- return graph
- def delFromGraph(graph, lst):
- def reducer(acc, elem):
- graph[elem[0]].discard(elem[1])
- #graph[elem[1]].discard(elem[0])
- functools.reduce(reducer, lst, None)
- return graph
- print(addToGraph(g, lst))
- print(delFromGraph(g, [(2,1), (3,1)]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement