Skip to content

All Problems

Problem 1

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

Sample Dictionary ( n = 5) :
Expected Output : {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}

Problem 2

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

1
2
3
4
5
6
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}

Problem 3

Write a Python function to combine two dictionary by adding values for common keys.

1
2
3
4
d1 = {'a': 100, 'b': 200, 'c':300}
d2 = {'a': 300, 'b': 200, 'd':400}

Output: Counter({'a': 400, 'b': 400, 'd': 400, 'c': 300})

Problem 4

Write a Python function to print the keys and values as seen below.

1
2
3
4
5
6
7
di = {'key1': 1, 'key2':2, 'key3': 3, 'key4':55}

Output:
key1 1
key2 2
key3 3
key4 4

Problem 5

Write a Python function to sort a dictionary by value. Return a list.

di = {5: 1, 4: 3, 2: 2, 6: 9, 3: 4}