Skip to content

Instantly share code, notes, and snippets.

@wanshot
Last active June 16, 2016 15:35
Show Gist options
  • Save wanshot/e2b0571d804a02bf29a3 to your computer and use it in GitHub Desktop.
Save wanshot/e2b0571d804a02bf29a3 to your computer and use it in GitHub Desktop.
class MultiKeyDict(dict):
"""
>>> format_ = MultiKeyDict({(f.name, f.status): f.id for f in User.objects.all()})
>>> format_.get(u"test")
1L
>>> format_.get(1)
1L
"""
def __init__(self, *args, **kwargs):
for a in args:
for k, v in a.items():
if isinstance(k, tuple):
self.update({x: v for x in k})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment