Skip to content

Instantly share code, notes, and snippets.

@TomFaulkner
Last active May 10, 2019 16:40
Show Gist options
  • Save TomFaulkner/5ef080c7b36fc8d8d3358667eb82c403 to your computer and use it in GitHub Desktop.
Save TomFaulkner/5ef080c7b36fc8d8d3358667eb82c403 to your computer and use it in GitHub Desktop.
Python JS Spread
# spread
# Author:- Rohit Tanwar
# https://github.com/kriadmin/30-seconds-of-python-code
# Contributors:-Rohit Tanwar
# Implements javascript's [].concat(...arr). Flattens the list(non-deep) and returns an list.
def spread(arg):
ret = []
for i in arg:
if isinstance(i, list):
ret.extend(i)
else:
ret.append(i)
return ret
"""
>>>spread([1,2,3,4,5, [6,7,8]])
[1, 2, 3, 4, 5, 6, 7, 8]
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment