Contact: aviboots(AT)netvision.net.il
43,700 questions
57,013 answers
573 users
dict = { 0: {'key1':34, 'key2':89, 'key3':12}, 1: {'key4':72, 'key5':90} } print(dict) ''' run: {0: {'key1': 34, 'key2': 89, 'key3': 12}, 1: {'key4': 72, 'key5': 90}} '''
dict = { 0: {'key1':34, 'key2':89, 'key3':12}, 1: {'key4':72, 'key5':90} } print(dict[0]['key2']) ''' run: 89 '''
dict = { 0: {'key1':34, 'key2':89, 'key3':12}, 1: {'key4':72, 'key5':90} } print(dict[1]) ''' run: {'key4': 72, 'key5': 90} '''
dict = { 0: {'key1':34, 'key2':89, 'key3':12}, 1: {'key4':72, 'key5':90} } dict[2]= {'key6':176, 'key7':120} print(dict) ''' run: {0: {'key1': 34, 'key2': 89, 'key3': 12}, 1: {'key4': 72, 'key5': 90}, 2: {'key6': 176, 'key7': 120}} '''
from collections import defaultdict d = defaultdict(lambda: defaultdict(dict)) d['key_outer_1'] = {'key_inner_1':'val1', 'key_inner_5':'val5'} d['key_outer_2'] = {'key_inner_2':'val2'} d['key_outer_3'] = {'key_inner_3':'val3'} print(dict(d)) ''' run: {'key_outer_1': {'key_inner_1': 'val1', 'key_inner_5': 'val5'}, 'key_outer_2': {'key_inner_2': 'val2'}, 'key_outer_3': {'key_inner_3': 'val3'}} '''