Flatten a list of lists by one level using idiomatic Python.
Answer
A nested list comprehension is concise when the input is explicitly one level deep: iterate over each inner collection and then over each item inside it. The comprehension preserves left-to-right order and creates one new list. It should not be presented as a recursive flattening solution because deeper arbitrary nesting needs different logic.
Strong answer includes
- uses a nested comprehension correctly
- preserves input order
- distinguishes one-level flattening from recursive flattening
Practical example
Python
Result
Run the code to see the result.
The first `for` chooses each inner list; the second yields each item from that list into the output.
Expected result: [1, 2, 3, 4]