Programming Examples

Write a Python program to find the length of a dictionary.


Write a Python program to find the length of a dictionary.

If input is: {“England”: “London”, “Italy”: “Rome”} then output should be: 2

If input is: {10: “ten”, 20: “twenty”, 30: “thirty”} then output should be: 3

If input is: {} then output should be: 0

Solution

d = eval(input("Enter a dictionary: "))

print("Length of dictionary:", len(d))
Output

Input: {"England": "London", "Italy": "Rome"}

Output: Length of dictionary: 2


Input: {10: "ten", 20: "twenty", 30: "thirty"}

Output: Length of dictionary: 3


Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad