136k views
3 votes
The variable most_recent_novel is associated with a dictionary that maps the names of novelists to their most recently published novels. Write a statement that replaces the value "Harry Potter and the Half-Blood Prince" with the value "Harry Potter and the Deathly Hallows" for the key "J.K. Rawling". Note: we realize that we have unfortunately misspelled the author's name. We will correct this error at a future date.

User Johnrad
by
5.2k points

1 Answer

4 votes

Answer:

most_recent_novel["J.K. Rawling"] = "Harry Potter and the Deathly Hallows"

Step-by-step explanation:

Presume that there is a dictionary with an initial mapping as follows:

most_recent_novel = {

"J.K. Rawling" : "Harry Potter and the Half-Blood Prince"

}

The dictionary has one key, "J.K. Rawling", and its associated value "Harry Potter and the Half-Blood Prince". To replace the value of "J.K. Rawling" key, we can just use the syntax

dict_name[key_name] = new_value

This will be set a new value to the key which will overwrite the previous value.

User Volodymyr Frytskyy
by
4.0k points