Jan-30-2018, 09:22 PM
Hi everyone,
I am a bit confused on this concept.
I understand it is a dictionary of dictionaries but here is where I am confused: A dictionary contains key / value pairs.
Well here we have a nested dictionary:
When I use the keys method I get this:
['transfer_dummy', 'callback_dummy', 'appt_dummy']
When I use the values method I get this:
[{'unit': '%', 'label': 'transfer', 'classifier': 1, 'id': 11, 'direction': '+', 'demo': 1, 'value': 900}, {'unit': '%', 'label': 'call back', 'classifier': 1, 'id': 10, 'direction': '+', 'demo': 0, 'value': 900}, {'unit': '%', 'label': 'appointment', 'classifier': 1, 'id': 12, 'direction': '+', 'demo': 1, 'value': 900}]
So it appears keys in dictionaries only nest 1 level deep?
I understand how to swap out the keys from method but i can't figure out how to swap out the id key and why python is calling this a value.
I am a bit confused on this concept.
I understand it is a dictionary of dictionaries but here is where I am confused: A dictionary contains key / value pairs.
Well here we have a nested dictionary:
kpis_dict = {'transfer_dummy': {'unit': '%', 'label': 'transfer', 'classifier': 1, 'id': 11, 'direction': '+', 'demo': 1, 'value': 900}, 'callback_dummy': {'unit': '%', 'label': 'call back', 'classifier': 1, 'id': 10, 'direction': '+', 'demo': 0, 'value': 900}, 'appt_dummy': {'unit': '%', 'label': 'appointment', 'classifier': 1, 'id': 12, 'direction': '+', 'demo': 1, 'value': 900}} kpis_dict2 = {id: kpi_dict for id, kpi_dict in kpis_dict.items()} test = kpis_dict.values() a= list(test) print (a)I am trying to swap out id with transfer dummy. So basically take the key and swap it out with what I thought was another key (id being the key to value 11)
When I use the keys method I get this:
['transfer_dummy', 'callback_dummy', 'appt_dummy']
When I use the values method I get this:
[{'unit': '%', 'label': 'transfer', 'classifier': 1, 'id': 11, 'direction': '+', 'demo': 1, 'value': 900}, {'unit': '%', 'label': 'call back', 'classifier': 1, 'id': 10, 'direction': '+', 'demo': 0, 'value': 900}, {'unit': '%', 'label': 'appointment', 'classifier': 1, 'id': 12, 'direction': '+', 'demo': 1, 'value': 900}]
So it appears keys in dictionaries only nest 1 level deep?
I understand how to swap out the keys from method but i can't figure out how to swap out the id key and why python is calling this a value.