python 怎么快速获取嵌套列表内的每一个元素?

2024-12-04 16:29:29
推荐回答(2个)
回答1:

aa = [[(55736,)], [(55739,)], [(55740,), (55801,)], [(55748,)], [(55783,), (55786,), (55787,), (55788,)], [(55817,), (55821,)], [(55818,)]]
def getelement(aa):
    for elem in aa:
        if type(elem)==type([]):
            for element in getelement(elem):
                yield element
        else:yield elem
for elem in getelement(aa):print(elem)(55736,)
(55739,)
(55740,)
(55801,)
(55748,)
(55783,)
(55786,)
(55787,)
(55788,)
(55817,)
(55821,)
(55818,)

回答2:

for b in aa:
for bb in b:

print(bb)