easy +7 pts

Zip lists into pairs

Combine two sequences of any length into a list of sublists, stopping at the shorter input.

Write a function `zip_lists(list1, list2)` that returns a list of two-element lists (sublists). Each sublist contains the element from `list1` and the element from `list2` at the same index. The result must have exactly as many sublists as the length of the shorter input list. If either list is empty, return an empty list. Do not use Python's built-in `zip` function.

Constraints

0 ≤ len(list1), len(list2) ≤ 1000. Elements can be integers, strings, floats, or a mix. Use a loop or list comprehension.

Example

>>> zip_lists([1, 2, 3], ['a', 'b', 'c'])
[[1, 'a'], [2, 'b'], [3, 'c']]
>>> zip_lists([1, 2], ['x', 'y', 'z'])
[[1, 'x'], [2, 'y']]
>>> zip_lists([], [1, 2, 3])
[]
7 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

The number of pairs is min(len(list1), len(list2)).
Use indexing with a range from 0 to the shorter length.
A list comprehension is the cleanest way to build the result.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.