1) Write a program to get the input of key and value of the element in dictionary.
Display the key-value pair in the python dictionary format and find the length of the dictionary
Refer sample input and output for formatting specification.
All float values are displayed correct to 2 decimal places.
All text in bold corresponds to input and the rest corresponds to output.
TEST CASE 1
INPUT
3
23
33
43
32
33
34
OUTPUT
The dictionary is
{23: 32, 33: 33, 43: 34}
Length of dictionary is
3
Answers
Answered by
0
Program:
key = []
value = []
n = int(input("Enter number of key value pairs : "))
print("Enter keys : ")
for i in range(0, n):
k = int(input())
key.append(k)
print("Enter values : ")
for i in range(0, n):
v = int(input())
value.append(v)
dic = {}
for i in key:
for j in value:
dic[i] = j
value.remove(j)
break
print("The dictionary is",dic)
print("Length of dictionary is",n)
Output:
Enter number of key value pairs : 3
Enter keys :
23
33
43
Enter values :
32
33
34
The dictionary is {33: 33, 43: 34, 23: 32}
Length of dictionary is 3
Similar questions