Flatten the Array
def isiterable(anyObject):
if hasattr(anyObject, '__iter__') and not type(anyObject) is str:
if len(anyObject) > 0:
if not next(iter(anyObject)) == anyObject:
return True
else:
return False
def flattenArrayN(inputArray, flatList=0):
if flatList == 0:
flatList = []
for item in inputArray:
if isiterable(item):
if type(item) is dict:
for pair in item.items():
flattenArrayN(pair, flatList)
else:
flattenArrayN(item, flatList)
else:
flatList.append(item)
return flatList
The code works for an type of array, which is very important.
Run it on online IDE - Link