“Python flach eine Liste von Listen ab” Code-Antworten

Python, wie man eine Liste verflachert

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

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

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

Python Flacherliste

itertools.chain.from_iterable(factors)
Blushing Butterfly

Python flach eine Liste von Listen ab

from collections.abc import Iterable

def flatten(l):
    for el in l:
        if isinstance(el, Iterable) and not isinstance(el, (str, bytes)):
            yield from flatten(el)
        else:
            yield el
Strange Stag

Ähnliche Antworten wie “Python flach eine Liste von Listen ab”

Fragen ähnlich wie “Python flach eine Liste von Listen ab”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen