Answers for "Nested list into flat list python"

0

Nested list into flat list python

def flatten_list(_2d_list):
    flat_list = []
    # Iterate through the outer list
    for element in _2d_list:
        if type(element) is list:
            # If the element is of type list, iterate through the sublist
            for item in element:
                flat_list.append(item)
        else:
            flat_list.append(element)
    return flat_list

nested_list = [[1, 2, 3, 4], [5, 6, 7], [8, 9, 10]]
print('Original List', nested_list)
print('Transformed Flat List', flatten_list(nested_list))
Posted by: Guest on October-01-2021

Code answers related to "Nested list into flat list python"

Python Answers by Framework

Browse Popular Code Answers by Language