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))
▶ RUN

Output/ Explanation:

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

Output: Length of dictionary: 2


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

Output: Length of dictionary: 3


Latest Current Affairs 2026 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad