Code Fellows 401
Day 08 Notes
Home
Reading
List Comprehensions
Audio
Listen (optional): Debugging with PySnooper
Bookmark and Review
Primer on Decorators
Things I want to know more about
- List comprehensions are a concise way to create a list in Python.
- They are a combination of a loop and an expression, used to generate a new list based on an existing list or other iterable.
- They have the form of [expression for item in iterable] or [expression for item in iterable if condition]
- List comprehensions can be used to perform a simple operation on each item of an iterable, such as a list, tuple or a string.
- They are also faster and more memory efficient than equivalent for loop and filter function constructs
- List comprehensions can also be nested to create a more complex list.