Basic List Comprehensions
List comprehensions provide a concise way to create lists.
Basic Syntax
Loading Python Playground...
Exercises
Loading Python Exercise...
Loading Python Exercise...
Working with Strings
Loading Python Playground...
Loading Python Exercise...
Using Functions
Loading Python Playground...
Nested Iteration
Loading Python Playground...
Loading Python Exercise...
From Different Sources
Loading Python Playground...
Practice Playground
Loading Python Playground...
Key Takeaways
- Syntax:
[expression for item in iterable] - Replaces simple loops with
append() - Works with any iterable (list, string, range, etc.)
- Can call functions in the expression
- Nested:
[x for row in matrix for x in row] - More Pythonic and often faster than loops

