List Comprehension (Python)
A list comprehension is a concise, one-line way to build a new list by transforming or filtering an existing iterable.
Python
Syntax
[expression for item in iterable if condition]Examples
Python
squares = [n * n for n in range(5)]
print(squares)Output:
[0, 1, 4, 9, 16]