You can use for loop to flatten a list of lists in Python as shown below –
1 2 3 4 5 6 7 8 9 |
listoflists = [[1,2,3],[4,5],[6,7,8]] flat_list = [item for sublist in listoflists for item in sublist] print(flat_list) print(type(flat_list)) ## Returns ## [1, 2, 3, 4, 5, 6, 7, 8] ## |