flatten a list of list python

50

python how to flatten a list -

flat_list = [item for sublist in l for item in sublist]

python flat list from list of list -

flat_list = [item for sublist in l for item in sublist]

#which is equivalent to this 
flat_list = []
for sublist in l:
    for item in sublist:
        flat_list.append(item)

flatten a list of lists python -

flattened = [val for sublist in list_of_lists for val in sublist]

flatten lists python -

flat_list = []
for sublist in l:
    for item in sublist:
        flat_list.append(item)

Comments

Submit
0 Comments