xxxxxxxxxx
case_list = []
for entry in entries_list:
case = {'key1': entry[0], 'key2': entry[1], 'key3':entry[2] }
case_list.append(case)
xxxxxxxxxx
def list_of_lists_to_dictionary(list_of_list, key_col=0, val_col=1):
# Create empty dictionary
value_dict = {}
# Iterate through list and add to dictionary
for value in list_of_list:
v = {value[key_col]: value[val_col]}
value_dict.update(v)
return value_dict
xxxxxxxxxx
'''
There are 5 items with list as a key. To add a new item 'F' to the dictionary
you would want to use list(d.items()) in for loop
'''
d = {'A': [1, 5, 6, 7], 'B':[4, 5, 6, 7, 9], 'C':[12 ,4, 6, 3, 6], 'D':[23, 5, 7, 23, 12], 'E':[22, 2, 1, 4, 6]}
i = 1 #just for conditional
asc_ltr = 70 #asci value for letter 'F'
for k, v in list(d.items()):
if i == 3:
d['A'].append(50) #just checking the extra condition
else:
#to create a new key and value
d.update({chr(asc_ltr): [np.mean(v), 20, 30, 40]})
i += 1