Skip to content

Instantly share code, notes, and snippets.

@bussyjd
Created November 5, 2019 06:09
Show Gist options
  • Save bussyjd/e0918657ca2bb65ee9d1b6cec55ef8f9 to your computer and use it in GitHub Desktop.
Save bussyjd/e0918657ca2bb65ee9d1b6cec55ef8f9 to your computer and use it in GitHub Desktop.
silversurfer@SilverXPS:~$ python3.7 -i flatten.py >>> runit() [1, 2, 3, 4]
def flatlist(input):
result = []
for item in input:
# It's a int? store it!
if isinstance(item, int):
result.append(item)
#print(item)
# It's a list? Run through it!
elif isinstance(item, list):
result += flatlist(item)
#print(item)
return result
def runit():
result = flatlist([[1,2,[3]],4])
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment