开发者

python recursion problem [duplicate]

This question already has answers here: Closed 11 years ago.

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 recursi开发者_运维知识库on 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]


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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜