Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Why Use the map() Function?

Give Feedback

Now that you know how to use the map() function, you’ll review why you might want to use it. You can use this function to write your code in a functional way to input an immutable data structure and define the transformations you want to make, in a declarative way.

When you take this approach, you have a series of steps that are independent from each other and don’t modify your data set. This allows you to keep adding more steps to your program, avoid side effects, and ensure that your data set is still usable.

00:00 Well, if you’re wondering what this is good for—like, mapping functions across a list of things—so here, we could do all kinds of things. Like, we could add all kinds of computed properties, right?

00:10 Like, I could maybe uppercase the name. You can transform your input data in

00:18 all kinds of ways. And the nice thing is if you write your code in this fashion where it’s “functional”, in the sense that you’re taking an input that’s an immutable data structure—so, something that we had up here—and you define those transformations in a

00:36 declarative way like this, or with a list comprehension, or, you know, what we had further down. And you do this, then you have this series of steps that are completely independent from each other. You know, what we did down there—it didn’t modify this list at all.

00:54 It just took this list as an input—or, this tuple as an input, and then generated a new list. We could keep adding more steps to it and they would all be reusable and there would be no side effects.

01:06 Like, we’re not actually reaching into this thing and destroying this data structure or modifying it, but instead, we’re creating a new derived list, or derived iterable, from the input

01:19 data. And that’s kind of a cool concept. It makes things a lot simpler if you’re talking about parallel computation and it’s a very, very powerful concept, just from a mindset perspective, not necessarily from the perspective that you should write all of your Python code exactly like this and always use this style of programming. That would probably drive some people nuts. Here, you learned how to use the map() function. All right!

01:43 So, thanks for listening. Happy Pythoning! I’ll talk to you in the next video.

amicablezebra on April 16, 2020

Seems slightly sloppy with calling things a ‘list’? Happens kinda frequently when he calls a tuple a list. Sorta freaked me out.

Become a Member to join the conversation.