I know this has been asked before but I don't see any solutions for when there is a list of the type:
original_list = [[1,2], [3], [4,5,[6]]]
Tried this method:
def flatten(list):
"""Given a list that contains elements and other lists, this
will return a new list that has no sublists ("flattened")"""
flat = [] # new empty list to populate with flattened list
for sublist in list: # iterate through list elements
for element in sublist: #
flat.append(element)
return flat
print(flatten([1,2,3]))
This method too:
old_list = [[1,2], [3], [4,5,[6]]]
flat1 = []
flat1 = [sum(old_list, [])] # 1 layer deep
flat2 = []
flat2 = [sum(flat1), []] # 2 layers deep
print(sort2)
Not having any luck... tips? Thanks!