Zip Function in Python
zip() Use Cases
Pair Two Lists
list(zip(names, ages)) creates [(name, age), ...] tuples.
Iterate Together
for n, a in zip(names, ages): loops two lists in parallel.
Transpose Matrix
list(zip(*matrix)) flips rows and columns.
Unzip
names, ages = zip(*pairs) splits paired data back into separate lists.
Noble Desktop's Python Programming Immersive covers AI APIs, data analysis, and modern Python development.
1Full Video Transcript
Hi, my name is Zaret. I teach Python and in this video I'm going to show you another Python built-in function called zip. Now I hope by now you know where to find Python built-in functions. If you don't know, you could just Google "Python built-in functions" and that search will take you to the official Python documentation. You see built-in functions—Python comes with built-in functions. By the way, if you're serious about Python, bookmark this page. And the function that I'm about to show you is the function zip. It's right here. All right, so let me show you how it works.
2Setting Up Example Data
Suppose we have a string. Let's create a word, and word is "apple." All right. Now then we could create a list, and here we're going to have also a couple of items: 100, 200, 300, 400, and let's do one more, 500. Now what I want to emphasize here is that you could use the function len and you could see how many characters you got in your word. So obviously here you could count them, but in real life you don't want to count them because they might be too many. So here we got five, and you could run the same function len on that list and here we got also five.