stangurrr / congress_whowhat

1 stars 1 forks source link

flattening list of lists #1

Closed mynameisvinn closed 6 years ago

mynameisvinn commented 6 years ago

we have d, a list of lists.

a = [1, 2, 3]
b = [4, 5, 6]
c = [7, 8, 9]
d = [a, b, c]  # [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

let's flatten it.

flat_d = []

for sub_list in d:
    for element in sub_list:
        flat_d.append(element)

print(flat_d)  # [1, 2, 3, 4, 5, 6, 7, 8, 9]