11.5 Copy in Python Challenges

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Copy in Python Challenges

# Question

1. Assume you have list_1 = [2, 6, 9, 21], write a Python program to:

a. Create list_2 where list_2 is a deep copy of list1

b. Change the third element of lis_1 to 3

c. Reprint list_2

d. Is list_2 same to list_1

Expected output:

a. list_2 = [2, 6, 9, 21]

b. list_1 = [2, 6, 3, 21]

c. list_2 = [2, 6, 9, 21]

d. False

Kuala Lumpur, Malaysia, phone: +601160906599, e-mail:academysamer@gmail.com


# Question

2. Assume you have dic_1 = {'course': 'Python', 'level': 'beginner'}, write a Python program

to:

a. Create dic_2 where dic_2 is a shallow copy of dic1.

b. Change the value of level key to 'Advance' in dic_1

c. Reprint dic_2

d. Is dic_2 the same to dic_1

Expected output:

a. dic_2 = {'course': 'Python', 'level': 'beginner'}

b. dic_1 = {'course': 'Python', 'level': 'Advance'}

c. dic_2 = {'course': 'Python', 'level': 'Advance'}

d. True

To find out more about Python, web development, and data science visit us on:

Kuala Lumpur, Malaysia, phone: +601160906599, e-mail:academysamer@gmail.com

You might also like