Sha256: 0dbe31fa4237bcbf95e0a2e1d78a6ed22af823e53ab41d3016b1af1961c1c424

Contents?: true

Size: 426 Bytes

Versions: 387

Compression:

Stored size: 426 Bytes

Contents

def is_iterable(thing):
    try:
        iter(thing)
    except TypeError:
        return False
    else:
        return True


def flatten(iterable):
    """Flatten a list of lists."""
    flattened = []
    for item in iterable:
        if is_iterable(item) and not isinstance(item, (str, bytes)):
            flattened += flatten(item)
        elif item is not None:
            flattened.append(item)
    return flattened

Version data entries

387 entries across 387 versions & 1 rubygems

Version Path
trackler-2.2.1.98 tracks/python/exercises/flatten-array/example.py
trackler-2.2.1.97 tracks/python/exercises/flatten-array/example.py
trackler-2.2.1.96 tracks/python/exercises/flatten-array/example.py
trackler-2.2.1.95 tracks/python/exercises/flatten-array/example.py
trackler-2.2.1.94 tracks/python/exercises/flatten-array/example.py
trackler-2.2.1.93 tracks/python/exercises/flatten-array/example.py
trackler-2.2.1.92 tracks/python/exercises/flatten-array/example.py
trackler-2.2.1.91 tracks/python/exercises/flatten-array/example.py
trackler-2.2.1.90 tracks/python/exercises/flatten-array/example.py
trackler-2.2.1.89 tracks/python/exercises/flatten-array/example.py
trackler-2.2.1.88 tracks/python/exercises/flatten-array/example.py
trackler-2.2.1.87 tracks/python/exercises/flatten-array/example.py
trackler-2.2.1.86 tracks/python/exercises/flatten-array/example.py
trackler-2.2.1.85 tracks/python/exercises/flatten-array/example.py
trackler-2.2.1.84 tracks/python/exercises/flatten-array/example.py
trackler-2.2.1.83 tracks/python/exercises/flatten-array/example.py
trackler-2.2.1.82 tracks/python/exercises/flatten-array/example.py
trackler-2.2.1.81 tracks/python/exercises/flatten-array/example.py
trackler-2.2.1.80 tracks/python/exercises/flatten-array/example.py
trackler-2.2.1.79 tracks/python/exercises/flatten-array/example.py