From the course: Python Functions for Data Science

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Python zip() function

Python zip() function - Python Tutorial

From the course: Python Functions for Data Science

Start my 1-month free trial

Python zip() function

- [Instructor] Another powerful built-in function in Python is zip. Zip takes in two or more sequences as inputs and allows you to iterate through those sequences at the same time. To illustrate how zip can be used when working with data, I'll be walking through an example. Let's say that I have a sequence named points game one containing the number of points that each of five players scored in game one, and I also have a sequence named points game two, containing the number of points that each of five players scored in game two. Now say I want to compute the absolute difference in points scored between game one and game two for each of the five players. First, I'll initialize a sequence named diffs, which is where the differences in points will be saved once they're computed. Next, I'll write a for loop using zip to iterate through points game one and points game two at the same time. In each iteration, I'll use the…

Contents