Initializing two dimensional dictionary in Python
◯ usage
>>> table = dict2d(['a', 'b', 'c']) >>> table['a']['b'] = 100 >>> table['a']['b'] 100
◯ definition
def dict2d(key_list, default=None): return dict1d(key_list, dict1d(key_list, default)) def dict1d(key_list, default=None): n = len(key_list) default_list = [default]*n return dict(zip(key_list, default_list))