The programming language one, not the snake one!
Hello pals!
Some time ago, I came across a problem in which I had to flatten an array of objects. That is, the elements of the array can be primitives or arrays. The end results is to be an array of primitives.
I used python to implement this since it allows much more compact snippets for such jobs.
Here is the code 🙂
def flatten(lst):
return sum( ([x] if not isinstance(x, list) else flatten(x)
for x in lst), [] )
lst = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []]
print flatten(lst)
Continue reading “A little Python!” →