Advertisement
treyhunner

invert dict of sets in Python

Nov 15th, 2015
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.18 KB | None | 0 0
  1. def invert_final(d):
  2.     ret = defaultdict(set)
  3.     items = ((key, value) for key in d for value in d[key])
  4.     for key, value in items:
  5.         ret[value].add(key)
  6.     return ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement