Created
December 14, 2011 05:22
-
-
Save dketov/1475387 to your computer and use it in GitHub Desktop.
Перегрузка операторов
This file contains hidden or 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
# -*- encoding: utf-8 -*- | |
""" | |
Перегрузка операторов | |
""" | |
class defaultdict(dict): | |
def __init__(self, default=None): | |
dict.__init__(self) | |
self.default = default | |
def __getitem__(self, key): | |
try: | |
return dict.__getitem__(self, key) | |
except KeyError: | |
return self.default |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment