v Flatten Lists Of Lists - Python

Flatten Lists Of Lists

# Create a list containing three lists of names
list_of_lists = [['Amy','Betty','Cathryn','Dana'], 
                 ['Elizabeth','Fay','Gora'], 
                  ['Heidi','Jane','Kayley']]
# For each element in list_of_lists, take each element in the list
flattened_list = [i for row in list_of_lists for i in row]
# View the flattened list
flattened_list
['Amy',
 'Betty',
 'Cathryn',
 'Dana',
 'Elizabeth',
 'Fay',
 'Gora',
 'Heidi',
 'Jane',
 'Kayley']