Answer to Question #162012 in Python for Jody Williams

Question #162012

The below, python dictionary (my_fruits_dic) holds fruits and their price.

 

my_fruits_dic = {

    "Fruit": "Price", 

    "apple": 6.44, 

    "banana": 0.77, 

    "orange": 3.44,

}

 


(1) Add a new item "berries" with the value {blackberry: 1.24, blueberry: 3.14}.

Print myDic. (This new dictionary will be added without the berries key. It needs to be added as a nested dictionary under berries key).

1
Expert's answer
2021-02-08T05:09:36-0500

Here the answer:

my_fruits_dic = {
       'Fruit': 'Price',
       'apple': 6.44,
       'banana': 0.77,
       'orange': 3.44
       }

myDic = {'blackberry': 1.24, 'blueberry': 3.14}

my_fruits_dic['berries'] = myDic

for key, value in my_fruits_dic['berries'].items():
   print(key, " - ", value)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS