Created
February 7, 2013 20:32
-
-
Save felipe-prenholato/4733921 to your computer and use it in GitHub Desktop.
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
# -*- 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