“APLAPER LISTE EN PYTHON” Réponses codées

Python comment aplatir une liste

flat_list = [item for sublist in l for item in sublist]
Talented Thrush

Liste d'aplatissement Python

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

Python Flat List à partir de la liste de la liste

flat_list = [item for sublist in l for item in sublist]

#which is equivalent to this 
flat_list = []
for sublist in l:
    for item in sublist:
        flat_list.append(item)
Batman

APLAPER LISTE EN PYTHON

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

APLAPER LISTE EN PYTHON

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

APLAPER LISTE EN PYTHON

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

Réponses similaires à “APLAPER LISTE EN PYTHON”

Questions similaires à “APLAPER LISTE EN PYTHON”

Plus de réponses similaires à “APLAPER LISTE EN PYTHON” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code