“Flachliste” 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

Führen Sie eine Liste von Listen Python ab

flattened = [val for sublist in list_of_lists for val in sublist]
Disturbed Dogfish

Flach eine Liste der Listen -Python ab

# 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

Flachliste

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

Flachliste

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 “Flachliste”

Fragen ähnlich wie “Flachliste”

Weitere verwandte Antworten zu “Flachliste” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen