166k views
5 votes
Create a dictionary that maps a fruit name to its color. Both the keys and the values should be stored as strings. Include only the following three entries in the dictionary: apple (red), orange (orange), and banana (yellow). Store the dictionary in a variable named fruit_dictionary.

User Hsnbrg
by
5.9k points

1 Answer

3 votes

Answer:

Written in Python:

fruit_dictionary = {}

fruit_dictionary = {'apple': 'red', 'orange': 'orange', 'banana': 'yellow'}

Step-by-step explanation:

First (although, not necessary), we create an empty dictionary named fruit_dictionary on line 1

Next, we populate the dictionary using the following syntax:

{key-1:value-1, key-2:value-2,......,key-n:value-n}

In this case, the entry would be:

{'apple': 'red',

'orange': 'orange',

'banana': 'yellow'}

The items on the first column (i.e. apple, orange and banana) are the keys while the items on the second (i.e. red, orange and yellow) are the values of the dictionary

To print the items in the dictionary, you can add the following line of code:

print(fruit_dictionary.items())

User Pritesh
by
6.1k points