Question
You have been given a dictionary and a list of tuples. Tuple has (key, value) pair. Write a program that prints a dictionary where the
You have been given a dictionary and a list of tuples. Tuple has (key, value) pair. Write a program that prints a dictionary where the values corresponding to those keys don't exist. Hint: use isinstance(value_to_check_type, data_type) for checking data type of values of dictionary
================================================
Given Input 1: dict1 = {"name": ["Alice", "Bob"], "initial": "F44", "city": "Dhaka"} list1= [("name", "Alice"), ("initial", "F44"), ("city", "Naogaon")]
Sample Output 1: {"name": "Bob", "city": "Dhaka"}
Explanation 1: Here the value of the key, value pair in the dictionary can be in list form. If unmatched values are greater than 1, then you need to put them into a list and add it to the output dictionary as a list. If it is one then you can just simply add it. Here for the name key we have one unmatched value which is Bob and for the city key we have one unmatched value which is Dhaka''. So, our output becomes, {"name": "Bob", "city": "Dhaka"}
================================================
Given Input 2: dict1= {"name": ["Alice", "Bob", "Martha"], "initial": "F44", "city": "Dhaka"} list1= [("name", "Alice"), ("initial", "F44"), ("city", "Dhaka")]
Sample Output 2: {"name": ["Bob", "Martha"]}
You have been given a dictionary and a list of tuples. Tuple has (key value) pair. Write a program that prints a dictionary where the values corresponding to those keys don't exist Hint use isinstance(value_to_check_type, data_type) for checking data type of values of dictionary Given Input 1: dictt = {"name": ["Alice", "Bob"), "Initial":"44","city": "Dhaka" list1= f("name", "Alice"). ("Initiar. "F44"), ("city". "Naogaon")] Sample Output 1: {": : {"name": "Bob", "city": "Dhaka"} Explanation 1: Here the value of the key, value pair in the dictionary can be in list form. If unmatched values are greater than 1, then you need to put them into a list and add it to the output dictionary as a list. If it is one then you can just simply add it Here for the "name" key we have one unmatched value which is "Bob" and for the city" key we have one unmatched value which is "Dhaka" So, our output becomes {"name": "Bob", "city": "Dhaka"} Given Input 2: dict1= {"name": ["Alice", "Bob", "Martha"), "Initial": "F44","city": "Dhaka"} list1= [("name", "Alice"). ("Initial". "F44"). ("city". "Dhaka")] Sample Output 2: {"name": ["Bob", "Martha"}Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started