CODEX

Python List Comprehension: One-Liner For Loops

Comprehensions offer a smooth approach for creating new sequences in a concise and readable way.

Artturi Jalli
CodeX
Published in
3 min readFeb 11, 2021

--

Photo by Sebastian Willius on Unsplash

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

Python List Comprehension

--

--

Artturi Jalli
CodeX
Writer for

Check @jalliartturi on YouTube to become a successful blogger. (For collabs, reach me out at: artturi@bloggersgoto.com)