Python Program to Flatten a Nested List (Using Nested for Loops (non pythonic way))

bookmark

my_list = [[1], [2, 3], [4, 5, 6, 7]]

flat_list = []
for sublist in my_list:
    for num in sublist:
        flat_list.append(num)

print(flat_list)

 

Output

[1, 2, 3, 4, 5, 6, 7]