Python from Zero to Hero

toEpam
6,534 views

Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

Exercise 1

Write a Python script to concatenate the following dictionaries to create a new one.

Example input 1:

dic1 = {1: 10, 2: 20}
dic2 = {3: 30, 4: 40}

Expected Result : {1: 10, 2: 20, 3: 30, 4: 40}

Example input 2:

dic1 = {1: 10, 2: 20}
dic2 = {3: 30, 4: 40}
dic3 = {5: 50, 6: 60}

Output : {1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}

Merge dictionaries

Exercise 2

Write a Python script to generate and print a dictionary that contains a number (between 1 and n) in the form (x, x*x).

Example input 1:

n = 1

Expected Result : {1: 1}

Example input 2:

n = 5

Output : {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}

Merge dictionaries
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content