Zip Function
Multiple Choice Medium
Question
What does list(zip([1,2], ["a","b"])) return?
Hint
zip pairs elements from multiple iterables.
Explanation
list(zip([1,2], ["a","b"])) returns [(1, "a"), (2, "b")]. zip pairs elements from each iterable by position. It stops at the shortest iterable. Common uses: iterating pairs (for num, letter in zip(nums, letters)), creating dicts (dict(zip(keys, values))). Use itertools.zip_longest for unequal lengths.
Related Resources
Related Lessons
- Data Types
Learn Python data types.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.