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 - 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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Python: The functional parts1m 5s
-
(Locked)
Mapping4m 45s
-
(Locked)
Filtering3m 20s
-
(Locked)
Lambdas in Python4m 25s
-
(Locked)
List comprehensions in Python3m 35s
-
(Locked)
Reducing4m 53s
-
(Locked)
Combining list functions7m 15s
-
(Locked)
Challenge: Converting to list comprehensions52s
-
(Locked)
Solution: Converting to list comprehensions3m 30s
-
(Locked)
Solution: Practicing list comprehensions1m 46s
-
(Locked)
-
-
-