A multidimensional list like l=[[1,2],[3,4]] could be converted to a 1D one by doing sum(l,[]). Can anybody please explain how that happens?
l=[[1,2],[3,4]]
sum(l,[])
I've written this function:
def make_array_single_dimension(l): l2 = [] for x in l: if type(x).__name__ == "list": l2 += make_array_single_dimension(x) else: l2.append(x) return l2
It works as well!