Given a list of fruits, fruit_list, we would like to create dictionary called pr
ID: 3909522 • Letter: G
Question
Given a list of fruits, fruit_list, we would like to create dictionary called prices.
The keys in the dictionary are the fruit names from the list with an 's' added at the end.
The values corresponding to all the entries in the dictionary are 3: the price of all the fruits 3.
Write a dictionary comprehension for the dictionary prices.
Ex.:
fruit_list=['banana','apple','orange','pineapple','plum']
prices will be: {'bananas':3, 'apples':3,'oranges':3,'pineapples':3,'plums':3}
Your answer must be in the form of a dictionary comprehension.
Start with:
prices={
Explanation / Answer
fruit_list=['banana','apple','orange','pineapple','plum'] prices = {fruit: 3 for fruit in fruit_list} temp = {} for k,v in prices.items(): temp[k + 's'] = v prices = temp print(prices)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.