Python Dictionary values, multiple dictionaries


#1

How can I get the value of “project name” from each dictionary without the keys and values of all of the other dictionary keys and values i.e the value for “project name” only?

Cust1 = {‘project_name’: ‘ABC_Company’, ‘resources’: [‘m2xlarge’, ‘c4micro’], ‘cost’: 4500.00}

Cust2 = {‘project_name’: ‘DEF_Company’, ‘resources’: [‘m4xlarge’, ‘c4micro’], ‘cost’: 2500.00}

Cust3 = {‘project_name’: ‘GHI_Company’, ‘resources’: [‘c4micro’], ‘cost’: 500.00}


#2

simple:

Cust1['project_name']
Cust2['project_name']
Cust3['project_name']

we could also insert the dictionaries in a list, and then loop over the list.


#3

thank you for that answer - also, how to collect those together rather than as three separate things? for instance, I want to get all those values and print them together.


#4

let me phrase that better, we could create a list and store the dictionaries in it. This would mean having the dictionaries in a single place, and allow for looping

then loop over the list, inside the loop create a new list

.append() the values of the dictionary to the new list

then after the loop, use .join() to print all the values.


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.