Skip to content

Instantly share code, notes, and snippets.

@Beefster09
Created April 12, 2019 05:03
Show Gist options
  • Save Beefster09/7be682b8b28d90d5bbb5310efbf2f5e4 to your computer and use it in GitHub Desktop.
Save Beefster09/7be682b8b28d90d5bbb5310efbf2f5e4 to your computer and use it in GitHub Desktop.
Flatten an arbitrarily nested array with Python
import itertools
def flatten(seq):
if isinstance(seq, list):
return list(itertools.chain.from_iterable(map(flatten, seq)))
else:
return [seq]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment