A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a Python program to merge more than one dictionary in a single expression
Q:

Write a Python program to merge more than one dictionary in a single expression

0

Write a Python program to merge more than one dictionary in a single expression

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import collections as ct
def merge_dictionaries(color1,color2):
    merged_dict = dict(ct.ChainMap({}, color1, color2))
    return merged_dict
color1 = { "R": "Red", "B": "Black", "P": "Pink" }
color2 = { "G": "Green", "W": "White" }
print("Original dictionaries:")
print(color1,' ',color2)
print("\nMerged dictionary:")
print(merge_dictionaries(color1, color2))

def merge_dictionaries(color1,color2, color3):
    merged_dict = dict(ct.ChainMap({}, color1, color2, color3))
    return merged_dict

color1 = { "R": "Red", "B": "Black", "P": "Pink" }
color2 = { "G": "Green", "W": "White" }
color3 = { "O": "Orange", "W": "White", "B": "Black" }

print("\nOriginal dictionaries:")
print(color1,' ',color2, color3)
print("\nMerged dictionary:")
# Duplicate colours have automatically removed.
print(merge_dictionaries(color1, color2, color3))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now