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 split_dict_equally(input_dict, chunks=2): | |
"Splits dict by keys. Returns a list of dictionaries." | |
# prep with empty dicts | |
return_list = [dict() for idx in xrange(chunks)] | |
idx = 0 | |
for k,v in input_dict.iteritems(): | |
return_list[idx][k] = v | |
if idx < chunks-1: # indexes start at 0 | |
idx += 1 | |
else: |
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
class MyDict(dict): | |
def __init__(self, *args, **kwargs): | |
dict.__init__(self, *args, **kwargs) | |
def get(self, key, default=None): | |
print "getting key: %s" % key | |
return super(MyDict, self).get(key, default=default) |