“Lista aplanada” Código de respuesta

Lista de Python Flatten

l = [[1, 2], [3, 4], [5, 6, 7]]
flat_list = [item for sublist in l for item in sublist]
# flat_list = [1, 2, 3, 4, 5, 6, 7]
Wandering Willet

aplanar una lista de list python

# idiomatic python

# using itertools
import itertools

list_of_list = [[1, 2, 3], [4, 5], [6]]
chain = itertools.chain(*images)

flattened_list = list(chain)
# [1, 2, 3, 4, 5, 6]
Adventurous Alligator

Lista de Python Flatten

itertools.chain.from_iterable(factors)
Blushing Butterfly

Python List aplanar

nested_lists = [[1, 2], [[3, 4], [5, 6], [[7, 8], [9, 10], [[11, [12, 13]]]]]]
flatten = lambda x: [y for l in x for y in flatten(l)] if type(x) is list else [x]
flatten(nested_lists)
# [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
patrick204nqh

Lista aplanada

regular_list = [[1, 2, 3, 4], [5, 6, 7], [8, 9]]
flat_list = [item for sublist in regular_list for item in sublist]
print('Original list', regular_list)
print('Transformed list', flat_list)
Clever Caterpillar

Lista aplanada

regular_list = [[1, 2, 3, 4], [5, 6, 7], [8, 9]]
flat_list = [item for sublist in regular_list for item in sublist]
print('Original list', regular_list)
print('Transformed list', flat_list)
Clever Caterpillar

Respuestas similares a “Lista aplanada”

Preguntas similares a “Lista aplanada”

Más respuestas relacionadas con “Lista aplanada” en Python

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código