From the course: Python Functions for Data Science

Unlock the full course today

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

Python map() function

Python map() function - Python Tutorial

From the course: Python Functions for Data Science

Start my 1-month free trial

Python map() function

- [Instructor] There are several built-in Python functions that can be very useful when working with data. One such function is Map. Map takes in a function and a sequence as inputs, in that order, and returns an iterator that applies the given function to every item in the given sequence. To collect everything that lies in the result all at once, you can call List on the iterator that Map yields. Note that a List is a built-in Python feature that allows you to create a sequence. I'll be walking through an example to illustrate how Map can be used. Let's say say I have a dataset that contains students' grades across five exams. I defined a function named "lowest_grade" that takes in a student ID as input, and returns the lowest exam grade for the student with a given student ID. Also, I collected all the distinct student IDs from the dataset as a sequence, and saved it in a variable named "student_ids." Now, say I want…

Contents