Member-only story
7 Useful Ways To Use the Zip() Function in Python
Learn how the zip() function can make your life easier
Python has useful built-in functions that can make your life easier and save some lines of code without sacrificing quality.
Today, you are going to learn how to use the zip()
function. The zip()
function can be used to aggregate data from multiple iterables, such as lists. Here is an illustration:

What Is the zip() Function?
Before jumping into the use cases, let’s briefly introduce the zip()
function.
The zip()
function aggregates elements from iterables, such as two lists. It returns an iterator object.
For instance, let’s zip players and player numbers together:
Result:
[(7, 'Cristiano Ronaldo'), (9, 'Gareth Bale'), (10, 'Lionel Messi')]
The zip()
function creates tuples from the nth elements of both lists. All in all, the working principle is similar to that of a physical zipper.
You now know the basics of zip()
function. Let’s see what you can do with it.
1. Zip Any Number of Iterables
You are not restricted to zipping just two iterables.
For example, let’s zip three lists: