Dictionary From Two Lists

You are given two lists, one containing keys and the other containing values. Your task is to implement the create_dict function in Python, which takes these two lists and creates a dictionary that maps each key to its corresponding value.
The create_dict function should have three parameters: keys, values, and strict. keys and values are positional-only arguments representing the two lists you'll use to create the dictionary. strict is a keyword-only argument with a default value of False.
If strict is True, the function should return a string ValueError: Lists of different length if the lists keys and values are not the same length. If strict is False, the function should fill in any missing values with None.
The function should return the created dictionary or the error message.
The first line of the input contains space-separated elements in the keys. The next line contains space-separated elements in the values list. The last line will contain the strict mode value.
It’s guaranteed that the keys are unique and are always of type string and the values are integers.
The program should print the returned value of the function.
Input
Output
apple orange banana 100 200 300 False
{'apple': 100, 'orange': 200, 'banana': 300}
apple orange banana 100 200 True
ValueError: Lists of different length
apple orange banana 100 200 False
{'apple': 100, 'orange': 200, 'banana': None}
 

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue