Let's talk about zip.
How can we use zip?
Well, let's create a new function.
And the zip function works kind of like a zipper.
We need two lists or two intervals and we can zip them together.
Let me show you what I mean.
Let's say I have my list and then your list.
And this.
Your list will have ten, 20 and 30.
Make sure that it's a list.
There you go.
And in here with the zip function, I can simply run.
Zip.
And in here.
I give it as many eatables as I want in our case to intervals.
So I'm going to give it my list.
And your list.
Let's close that out.
Add one more bracket.
And if I click Run.
Look at that.
What just happened here.
Zip.
Like a zipper.
Takes the two balls and grabs the first item from each and zips them together like a zipper.
So one and ten get added to a tuple together.
Then two and 20 get added to a tuple together.
And then three and 30 get added to a tuple together.
What if this was a tuple?
Like this and I click Run.
Does it matter?
It's an iterable.
It's going to zip the items together.
Now, this may not seem that useful to you now.
It's actually a very important function that, because it's so generic, can be used in so many different
things.
For example, if we had from a database, we collected all the usernames from one column in a database
and then maybe from another part of the database.
We collect all of the phone numbers and they were all in the same order.
Well, we can combine these into a temple using zip that has the username and the phone numbers attached
to them and create a whole new data structure.
And if I had another list here, let's say their list.
And this one has five.
For.
And three, I can add again their list as well.
And if I click Run.
You see that?
I can keep zipping things together so zip iterates over each one of these lists or data structures and
zips them together.
Once again noticing that we don't modify any of our current.
Data.
Instead, we create a whole new one.
Very, very nice.
What about reduce?
Let's find out more in the next video.