Skip to content

Instantly share code, notes, and snippets.

@stober
Created May 10, 2011 18:14
Show Gist options
  • Save stober/965026 to your computer and use it in GitHub Desktop.
Save stober/965026 to your computer and use it in GitHub Desktop.
Flatten a Dictionary of Sets
def flat_dict(d):
"""
Return a dict where sets are replaced by a single element of each
set. Compose with create_rdict to reverse a 1-1 dict.
"""
nd = {}
for (key, value) in d.items():
nd[key] = value.pop()
return nd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment