Dict Clear in Python

Level 256 keystrokes

This removes all key-value pairs from a dictionary using clear().

Python code

# Create a dictionary with three key-value pairs
1data = {"a": 1, "b": 2, "c": 3}
# clear() removes every pair in place; data is still the same (now empty) dict object
2data.clear()
# Prints {} (an empty dictionary)
3print(data)

Output

{}
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Python code and how often they appear.

  • "× 6
  • :× 3
  • ,× 2
  • (× 2
  • )× 2
  • .× 1
  • {× 1
  • }× 1
  • =× 1

More Python examples at level 2

← Python typing practice