Dictionary Keys in Python

Level 256 keystrokes

This gets all keys from a dictionary. The keys() method returns a view of all dictionary keys.

Python code

# Create a dictionary with three key-value pairs
1data = {"a": 1, "b": 2, "c": 3}
# keys() returns a view of the keys in insertion order
# list() turns the view into a regular list, so it prints ['a', 'b', 'c']
2print(list(data.keys()))

Output

['a', 'b', 'c']
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
  • (× 3
  • )× 3
  • ,× 2
  • .× 1
  • {× 1
  • }× 1
  • =× 1

More Python examples at level 2

← Python typing practice