flatten_grid(grid) that takes a list of lists (a 2D grid where rows can have different lengths) and returns a single flat list containing every element in row-major order (row 0 fully, then row 1, and so on).grid = [[1, 2], [3], [4, 5, 6]]
[1, 2, 3, 4, 5, 6]
Elements are read row by row, left to right.
A nested loop appending each element works.
A list comprehension with two `for` clauses can also flatten it: [x for row in grid for x in row].