When Python programmers are asked about their favorite Python features, list comprehensions often make the list. They’re an example of Pythonic looping.
These lessons are part of a Real Python video course by Rich Bibby.
When Python programmers are asked about their favorite Python features, list comprehensions often make the list. They’re an example of Pythonic looping.
These lessons are part of a Real Python video course by Rich Bibby.
00:00 Hi, I’m Rich Bibby with realpython.com. Python is famous for allowing you to write code that’s elegant, easy to write, and almost as easy to read as plain English.
00:10 One of the language’s most distinctive features is the list comprehension, which you can use to create powerful functionality within a single line of code.
00:19 However, many developers struggle to fully leverage the more advanced features of a list comprehension in Python. Some programmers even use them too much, which can lead to code that’s less efficient and harder to read.
00:31 By the end of this tutorial, you’ll understand the full power of Python list comprehensions and how to use their features comfortably. You’ll also gain an understanding of the trade-offs that come with using them so that you can determine when other approaches are more preferable.
00:47
In this tutorial, you’ll learn how to rewrite loops and map calls as a list comprehension in Python; choose between comprehensions, loops, and map calls; supercharge your comprehensions with conditional logic; use comprehensions to replace filter()
; and profile your code to solve performance questions. So, let’s get started!
You must own this product to join the conversation.