Zip Lists in Python

Level 262 keystrokes

This pairs elements from two lists. The zip() function combines iterables element-wise into tuples.

Python code

# Create two lists to combine
1names = ["a", "b"]
2nums = [1, 2]
# zip() pairs elements from each list into tuples
# list() converts the zip object to a list for display
3print(list(zip(names, nums)))

Output

[('a', 1), ('b', 2)]
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.

  • "× 4
  • ,× 3
  • (× 3
  • )× 3
  • [× 2
  • ]× 2
  • =× 2

More Python examples at level 2

← Python typing practice