Flatten a List of Lists

Lab Python Intermediate 20 points

Read n, then n lines of integers. Print all numbers in one flat list using a nested comprehension.

Input

Line 1: n. Then n lines.

Output

The flat list.

Example

Input

3
1 2
3
4 5 6

Output

[1, 2, 3, 4, 5, 6]
Sample input available Sample output available
Editor
Python

Hints

The loops in a comprehension read in the same order as nested for statements.

Solution explanation

[x for row in rows for x in row] is the same as an outer loop over rows and an inner loop over x.

Show solution
n = int(input())
rows = [list(map(int, input().split())) for _ in range(n)]
print([x for row in rows for x in row])
Output
Answer
HOME LEARN COMMUNITY DASHBOARD