From the course: Functional Programming with Python
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
List comprehensions in Python - Python Tutorial
From the course: Functional Programming with Python
List comprehensions in Python
- [Instructor] Once you've gotten the hang of working with lists using the math and filter functions, you may be interested to discover that Python provides another way to do pretty much the same thing and that's by using something called list comprehensions. Put simply, list comprehensions are a nice readable way to both filter and transform the elements in a list. I usually think of them as a sort of combination of the three concepts we learned previously: map, filter and lambdas. So what do list comprehensions look like and how can we use them? Well, to answer this question, let's imagine, that as in the previous videos, we have a list of numbers that we want to transform in some way, whether it's by changing it to the elements by doubling them or by getting some subset of the elements, such as getting all the even numbers. So here's the basic syntax of using list comprehensions to do this. When we want to…
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 46s
-
(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)
-
-