Skip to content

Instantly share code, notes, and snippets.

@felipe-prenholato
Created February 7, 2013 20:32
Show Gist options
  • Save felipe-prenholato/4733921 to your computer and use it in GitHub Desktop.
Save felipe-prenholato/4733921 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, unicode_literals)
def flat_list(l):
result = []
for i, e in enumerate(l):
if type(e) is list:
result += e
else:
result += [e]
if len(result) == 1:
return result[0]
return result
def test_simple_list(l):
return all(map(lambda i: not isinstance(i, list), l))
if __name__ == '__main__':
origin = ['a', [['b'], 'c', ['d', ['e']]]]
print origin
while not test_simple_list(origin):
origin = flat_list(origin)
print origin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment