What is list comprehension and when to use it?
Answer
•Short syntax for creating a list.
•Example: [x*x for x in range(
•if x % 2 == 0].
•Readable compared to manual loop (if expression is simple).
•Use (...) for generator.
•Be careful with nested loops, don't overcomplicate.
Was this answer helpful?