-1

I've been looking through SO python's frequent question's and ended up in this one: Making a flat list out of list of lists in Python

So I was thinking about the case were you could have lists of lists of lists...

I came up with a code that seems to work (I have only tried the cases shown in the code), and I was wondering if there is any more pythonic way of writing it, since I come from other language and I'm not too much into list comprehension.

Community
  • 1
  • 1
Guimo
  • 632
  • 1
  • 7
  • 15
  • This is not how StackOverflow works; I think you want http://codereview.stackexchange.com, and the code should be *in the question*. – jonrsharpe Jun 28 '14 at 21:07
  • Oh I see, I'm sorry. Thanks for the two links provided, even though I can't reply to a comment in the one you marked mine being a duplicate of for not having enough reputation... Will take a look in codereview. Thanks again! – Guimo Jun 28 '14 at 21:11

1 Answers1

0
test = [[[1,2,3],[4,5]], [6], [[7],8]]
test2 = [[1,2,3],[4,5]]
test3 = [1,2,3]

def createSuperList(l):
    sol = []
    for item in l:
        if (type(item) is list):
            for item2 in createSuperList(item):
                sol.append(item2)
        else:
            sol.append(item)
    return sol

print (createSuperList(test))
print (createSuperList(test2))
print (createSuperList(test3))
Guimo
  • 632
  • 1
  • 7
  • 15