When is a list comprehension preferable to a loop?
Reveal the answer and explore the explanation.
08MediumWhen is a list comprehension preferable to a loop?
Answer
Medium
When is a list comprehension preferable to a loop?
Answer
Compact expression that constructs a list from an iterable with optional filtering.
Practical example
Square only positive values in a list.
Reference: Further reading ↗