Question
Python Question: Write a function called add_list_to_dict that has three parameters: dct , key , and lst . A dictionary, a key, and a list,
Python Question:
Write a function called add_list_to_dict that has three parameters: dct , key , and lst . A dictionary, a key, and a list, respectively.
Given the three parameters, the add_list_to_dict function returns a new dictionary with all of the key-value pairs from the original dictionary, and also sets a new key-value pair according to the given parameters. If anything besides a list is given as the third parameter, lst , the function should return a None-typed object.
my_dct = {'name': 'Smiley'}
my_list = [1, 3]
d = add_list_to_dict(my_dct, 'key', mylist)
print(d['key']) # --> [1, 3]
print(d['name']) # --> 'Smiley'
d2 = add_list_to_dict(my_dct, 'key', "I shouldn't add a string value.")
print(d2) @ --> None
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