Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions