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

Unlock This Lesson

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

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

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!


Sample Code (.zip)

3.5 KB


Course Slides (.pdf)

694.6 KB

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.

Christian Breiholz on June 19, 2021

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

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.

David S on Feb. 22, 2022

I really appreciated the clear examples and emphasis on readability!

Become a Member to join the conversation.