From the course: Functional Programming with Python

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Solution: Practicing list comprehensions

Solution: Practicing list comprehensions - Python Tutorial

From the course: Functional Programming with Python

Solution: Practicing list comprehensions

(techno upbeat music) - [Instructor] All right, well, hopefully, you've given this challenge a try. Let's take a look at the solution. So doubling with map was pretty straightforward. All we had to do here was say, map, and then pass numbers as the second argument there. Now, for the first argument, what we had to do was define our own function that would actually double a number, and that was pretty straightforward. So we'll just say return x * 2, and now we can say return (double, numbers). And you could have used a lambda expression here as well, right? You could have said, in fact, I'll show you how to do that. You could have said return map and then lambda x: x * 2, and that just allows you to do that in place there, in case you wanted to do that in a little bit more of a concise way, and that would've had the same effect, all right? So I'll just comment that out and leave that around for your reference. We'll use this old way of defining a function separately. All right, so…

Contents