Last active
May 10, 2019 16:40
-
-
Save TomFaulkner/5ef080c7b36fc8d8d3358667eb82c403 to your computer and use it in GitHub Desktop.
Python JS Spread
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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