MCPcopy
hub / github.com/dask/dask / flatten

Function flatten

dask/core.py:275–300  ·  view source on GitHub ↗

>>> list(flatten([1])) [1] >>> list(flatten([[1, 2], [1, 2]])) [1, 2, 1, 2] >>> list(flatten([[[1], [2]], [[1], [2]]])) [1, 2, 1, 2] >>> list(flatten(((1, 2), (1, 2)))) # Don't flatten tuples [(1, 2), (1, 2)] >>> list(flatten((1, 2, [3, 4]))) # support heter

(seq, container=list)

Source from the content-addressed store, hash-verified

273
274
275def flatten(seq, container=list):
276 """
277
278 >>> list(flatten([1]))
279 [1]
280
281 >>> list(flatten([[1, 2], [1, 2]]))
282 [1, 2, 1, 2]
283
284 >>> list(flatten([[[1], [2]], [[1], [2]]]))
285 [1, 2, 1, 2]
286
287 >>> list(flatten(((1, 2), (1, 2)))) # Don't flatten tuples
288 [(1, 2), (1, 2)]
289
290 >>> list(flatten((1, 2, [3, 4]))) # support heterogeneous
291 [1, 2, 3, 4]
292 """
293 if isinstance(seq, str):
294 yield seq
295 else:
296 for item in seq:
297 if isinstance(item, container):
298 yield from flatten(item, container=container)
299 else:
300 yield item
301
302
303T_ = TypeVar("T_")

Callers 15

_checkpoint_oneFunction · 0.90
_build_map_layerFunction · 0.90
unpack_collectionsFunction · 0.90
optimizeFunction · 0.90
get_asyncFunction · 0.90
cullFunction · 0.90
fuse_linearFunction · 0.90
fuseFunction · 0.90
computeFunction · 0.90
persistFunction · 0.90
get_collection_namesFunction · 0.90
_cull_dependenciesMethod · 0.90

Calls

no outgoing calls

Tested by 7

test_block_maskFunction · 0.72
test_flattenFunction · 0.72
optimizerFunction · 0.72
only_optimize_with_zFunction · 0.72
test_shuffleFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…