“Abflachungsliste in Python” Code-Antworten

Python, wie man eine Liste verflachert

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

Python Flacherliste

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 flache Liste aus der Liste der 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

Abflachungsliste in 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

Abflachungsliste in 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

Abflachungsliste in 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

Ähnliche Antworten wie “Abflachungsliste in Python”

Fragen ähnlich wie “Abflachungsliste in Python”

Weitere verwandte Antworten zu “Abflachungsliste in Python” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen