Skip to content

Instantly share code, notes, and snippets.

@arunmlvtec
arunmlvtec / flatten.py
Created September 18, 2017 07:44
Write some code, that will flatten an array of arbitrarily nested arrays of integers into a flat array of integers. e.g. [[1,2,[3]],4] -> [1,2,3,4].
""" Function takes an array of arbitrarily nested arrays of integers and flattens it into a 1 dimensional array. """
def flatten(inpArr):
outputArr = []
for element in inpArr:
if type(element) is int:
outputArr.append(element)
else:
outputArr += flatten(element)
return outputArr