[Type C]Q10. Write a function called addDict(dict1, dict2) which computes the union of two dictionaries. It should return a new dictionary, with all the items in both its arguments. If the same key appears in both arguments, feel free to pick a value from another.


Program code:

Clear Doubts with Computer Tutor
In case you’re facing problems in understanding concepts, writing programs, solving questions, want to learn fun facts | tips | tricks or absolutely anything around computer science, feel free to join CTs learner-teacher community: students.computertutor.in

Output:

{'a': 1, 'b': 2, 'c': 4, 'd': 5, 'e': 6}

A dictionary is a collection that is unordered, changeable, and indexed. In Python, dictionaries are written with curly brackets, and they have keys and values.

You can access the items of a dictionary by referring to its key name, inside square brackets.

Dictionaries are optimized to retrieve values when the key is known.

Basic python functionality is demonstrated in above program.

To view all the lessons in chapter 1: http://computertutor.in/class-12-computer-science/chapter-2/

To view entire class 12 computer science study material: http://computertutor.in/resources/

You cannot copy content of this page