0

Possible Duplicate:
Flatten (an irregular) list of lists in Python

hello I build a small program using recursion in Python, but am stuck in a place to solve the problem at least I do not know how to row, waiting for your help thank you in advance

intertwined with a list following the given problem using recursion I want to print on a single list.

example

this is my list

enter code here [[[13, 7], 90], 2, [1, 100], 8, 6]

expected result

enter code here[13,7,90,2,1,100,8,6]
Community
  • 1
  • 1
betul
  • 21
  • 1
    Three downvotes for this question? And no comments explaining to the new user what's wrong? Neither the headline he chose nor his text uses any words that would help him find the duplicate easily (e.g. "flatten"), so I doubt it's due to negligence. Might be bad luck, or lacking vocabulary. +1 to compensate. And welcome to SO betul, better luck with next question. :) – Lauritz V. Thaulow May 22 '11 at 19:31

1 Answers1

0

Like this:

startlist=[[[13, 7], 90], 2, [1, 100], 8, 6]
endlist=[]

def flatten(l):
    for item in l:
        if type(item) in (type([]),type(())):
            flatten(item)
        else:
            endlist.append(item)
AJ.
  • 27,586
  • 18
  • 84
  • 94