Find length of dictionary (number of key-value pairs) Dry Run in PYTHON

Find length of dictionary (number of key-value pairs) is an interactive PYTHON dry run visualizer from the Dict programs section. Study the source code, then use the execution controls to follow each step, variable update, highlighted line, and console output.

This page provides a browser-based dry run with source-code highlighting, auto-scroll, voice narration controls, and execution output for learning the program step by step.

Find length of dictionary (number of key-value pairs) Program Code

# Find length of dictionary using len()
student = {
    "name": "Alice",
    "age": 22,
    "course": "Physics",
    "grade": "A",
    "year": 3
}
print("Dictionary:", student)

# Using len() function
length = len(student)
print(f"Number of key-value pairs: {length}")

# Empty dictionary length
empty_dict = {}
print(f"\nEmpty dictionary length: {len(empty_dict)}")

# Manual counting using loop
count = 0
for key in student:
    count += 1
print(f"Manual count: {count}")

# Count after adding/removing
student["city"] = "Boston"
print(f"\nAfter adding 'city': {len(student)}")
student.pop("year")
print(f"After removing 'year': {len(student)}")

View the complete Dict programs page.

Program Console Find length of dictionary (number of key-value pairs) Topic: PYTHON Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.