38.4k views
5 votes
Complete the following code snippet so that all of the negative values my_dict will be changed to zero. for key, value in _______: if value my_dict[key]

User Paroxyzm
by
7.9k points

1 Answer

5 votes

Answer:

for key, value in my_dict.items():

my_dict[ key ] = 0 if value < 0

Step-by-step explanation:

Dictionary in python is an unordered and unindexed data structure, which is arranged in key-value pairs. To loop through the dictionary, the items() method is used on the dictionary finding the key and value on each iteration.

A value can be retrieved and changed using bracket notation and the key name of the value in question.

User Kallada
by
7.3k points