Created
May 10, 2011 18:14
-
-
Save stober/965026 to your computer and use it in GitHub Desktop.
Flatten a Dictionary of Sets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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