Display all key-value pairs Dry Run in PYTHON

Display all 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.

Display all key-value pairs Program Code

# Display all key-value pairs
inventory = {
    "apple": 50,
    "banana": 30,
    "orange": 25,
    "grape": 40
}
print("Dictionary:", inventory)

# Method 1: Using items() method
items_view = inventory.items()
print(f"\nUsing items(): {items_view}")
print(f"Type: {type(items_view)}")

# Method 2: Convert to list of tuples
items_list = list(inventory.items())
print(f"As list: {items_list}")

# Method 3: Iterate with items()
print("\nKey-Value pairs:")
for key, value in inventory.items():
    print(f"  {key} → {value}")

# Method 4: Pretty print
print("\nPretty print:")
for key, value in inventory.items():
    print(f"  Key: {key:10} Value: {value}")

View the complete Dict programs page.

Program Console Display all key-value pairs Topic: PYTHON Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.