Problem Statement
Explain list comprehension with an example.
Explanation
List comprehension is a compact way to create a new list by applying an expression to each element of an iterable. It replaces long loops with a single, readable line.
For instance, to build a list of squares you can write square equals x star star 2 for each x in a list. It is both faster and cleaner than using append inside a loop and is widely used in data transformation tasks.
Code Solution
SolutionRead Only
a=[1,2,3] squares=[x*x for x in a]
