How can you add multiple key-value pairs to an existing dictionary?

  • Using a for loop to iterate over a list of tuples, where each tuple contains a key-value pair, and using the update() method to add them to the dictionary.
  • By using the add() method and providing a list of key-value pairs.
  • Using the extend() method to append a list of key-value pairs to the dictionary.
  • By directly assigning a list of key-value pairs to the dictionary variable.
You can add multiple key-value pairs to an existing dictionary by using a for loop to iterate over a list of tuples, where each tuple contains a key-value pair, and then using the update() method to add them to the dictionary. The other options mentioned (add(), extend(), and direct assignment) are not standard methods for adding multiple key-value pairs to a dictionary.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *