CODEX
Python List Comprehension: One-Liner For Loops
Comprehensions offer a smooth approach for creating new sequences in a concise and readable way.
Published in
3 min readFeb 11, 2021
Python List Comprehension makes it possible to write concise one-liners for loops.
For instance, you can use a comprehension to replace this:
With this:
There are actually 4 different comprehensions in Python for the main collection types:
- List Comprehensions
- Dictionary Comprehensions
- Set Comprehensions
- Generator Comprehensions