Created
March 2, 2015 10:26
-
-
Save subramaniank/2005627003ae30846db2 to your computer and use it in GitHub Desktop.
Enum in python. Sequential and named enumerations with reverse_mapping(stable, given that enum values are unique)
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 enum(*sequential, **named): | |
enums = dict(zip(sequential, range(len(sequential))), **named) | |
reverse = dict((value, key) for key, value in enums.iteritems()) | |
enums['reverse_mapping'] = reverse | |
return type('Enum', (), enums) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment