Locked learning resources

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

Unlock This Lesson

Locked learning resources

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

Unlock This Lesson

Understanding Python List Comprehensions (Summary)

Whenever you have to choose a list creation method, try multiple implementations and consider what’s easiest to read and understand in your specific scenario. If performance is important, then you can use profiling tools to give you actionable data instead of relying on hunches or guesses about what works the best.

In this course, you learned how to:

  • Simplify loops and map() calls with declarative list comprehensions
  • Supercharge your comprehensions with conditional logic
  • Create set and dictionary comprehensions
  • Determine when code clarity or performance dictates an alternative approach

Remember that while Python list comprehensions get a lot of attention, your intuition and ability to use data when it counts will help you write clean code that serves the task at hand. This, ultimately, is the key to making your code Pythonic!

Download

Sample Code (.zip)

3.5 KB
Download

Course Slides (.pdf)

694.6 KB
Avatar image for Alan ODannel

Alan ODannel on April 7, 2021

Nice course, informative and flowed at a good pace. I had an understanding on Comprehensions, this course introduced concepts that I was not aware of. Thank you.

Avatar image for Christian Breiholz

Christian Breiholz on June 19, 2021

Really helpful. When I first list comprehensions, I was a bit overwhelmed. This tutorial made it clear!

Avatar image for MAStough

MAStough on Jan. 14, 2022

Nice brief introduction. Coupling this with the written article allowed me to pratice over in a Thonny file. I even picked up something beyond LC…timeit module! Thanks.

Avatar image for David S

David S on Feb. 22, 2022

I really appreciated the clear examples and emphasis on readability!

Avatar image for rwelk

rwelk on Feb. 13, 2024

Much information to take in on first viewing. I will do the reading then retake this lesson.Being relatively new to Python it take more time for the light bulb to turn on. I enjoyed the video.

Avatar image for akhilu15

akhilu15 on July 7, 2024

Good tutorial. Not only covers list comprehension but also compares with other alternatives.

Become a Member to join the conversation.