From the course: Python for JavaScript Developers
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
From JavaScript map and filter to an elegant Python comprehensions - Python Tutorial
From the course: Python for JavaScript Developers
From JavaScript map and filter to an elegant Python comprehensions
- [Instructor] Python has built-in map and filter functions. Most of the time though, you will see people map and filter using something called comprehension. Now, while comprehensions can be difficult to grasp at first, I think you have quite an advantage coming from JavaScript. You may really accelerate your learning using your knowledge of map and filter in JavaScript. So here, we have an array that goes from zero to four. So zero, one, two, three, four. Next, we use map to create a new array. Now, this array has each number of our original array plus one. So zero, one, two, three, four becomes one, two, three, four, five. Then, we have a filter, which allows us to produce a new array that only has numbers that are greater than two. So one, two, three, four, five becomes three, four, five. Now, suppose we wanted to do that with comprehensions. How would we go about it step by step? So we start with zero to four.…
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)
Iterating in Python3m 46s
-
(Locked)
Writing concise code with zip and enumerate3m 39s
-
(Locked)
From JavaScript map and filter to an elegant Python comprehensions6m 2s
-
(Locked)
Decorators are essential3m 35s
-
(Locked)
Challenge: Map to comprehension5m 19s
-
(Locked)
Solution: Map to comprehension2m 32s
-
(Locked)
-