CodeTestValidate

No installations needed! Write Python directly in your browser and get instant feedback with our smart validation system.

Challenge # 7

Merge Two Dictionaries

Objective

Combine the contents of two dictionaries into one.

Instructions

  • You are given two dictionaries: dict1 and dict2.

  • Merge dict2 into dict1 so that the result contains all key-value pairs from both dictionaries.

  • If a key exists in both, the value from dict2 should overwrite the one from dict1.

  • Print the merged dictionary.

Constraints:
Do not use input(). • Both variables are dictionaries.
Exemple IO

Input: dict1 = {'a': 1, 'b': 2} dict2 = {'b': 3, 'c': 4}

Output: {'a': 1, 'b': 3, 'c': 4}

Input: dict1 = {} dict2 = {'x': 10}

Output: {'x': 10}

Input: dict1 = {'x': 1} dict2 = {}

Output: {'x': 1}

Try It Online!

Output:

Validate Your Results

Get your code reviewed and validated to understand what you did right and where you can improve.

Previous challengeCount Character OccurrencesNext challengeCheck Anagrams
Loading...