Re:Why it’s hard for programmers to write a program to flatt...
by andr3w321 on Friday February 24, 2017 @04:18PM
(#13727985)
Some python 2
def flatten(x):
def flatten_generator(x):
if type(x) == list:
for y in x:
for z in flatten(y):
yield z
else:
yield x
return list(flatten_generator(x))
assert(flatten([1, [2,3]]) == [1,2,3])
ary = [1, [2,3], [4, [5,6]]]
print flatten(ary)