“Lista aninhada de Python” Respostas de código

Lista aninhada de Python

L = [[1, 2, 3],[4, 5, 6],[7, 8, 9]]   
for list in L:
    for number in list:
        print(number, end=' ')
# Prints 1 2 3 4 5 6 7 8 9
Homeless Herring

Como fazer uma lista da lista aninhada

>>> from collections import Iterable
def flatten(lis):
     for item in lis:
         if isinstance(item, Iterable) and not isinstance(item, str):
             for x in flatten(item):
                 yield x
         else:        
             yield item

>>> lis = [1,[2,2,2],4]
>>> list(flatten(lis))
[1, 2, 2, 2, 4]
>>> list(flatten([[1, 2, 3], [4, 5, 6], [7, 8, 9]]))
[1, 2, 3, 4, 5, 6, 7, 8, 9]
Shiny Seahorse

Listar listas aninhadas

x = [3, 4, [7, 8]]
print(x[2][1])
# 8
Sore Sloth

Lista de Python aninhada

nested_python_list = [[1,2,3], [4, 5, 6], [7, 8, 9]]
Outrageous Ostrich

Respostas semelhantes a “Lista aninhada de Python”

Perguntas semelhantes a “Lista aninhada de Python”

Mais respostas relacionadas para “Lista aninhada de Python” em Python

Procure respostas de código populares por idioma

Procurar outros idiomas de código