MCPcopy Create free account
hub / github.com/dask/dask / ndeepmap

Function ndeepmap

dask/utils.py:303–319  ·  view source on GitHub ↗

Call a function on every element within a nested container >>> def inc(x): ... return x + 1 >>> L = [[1, 2], [3, 4, 5]] >>> ndeepmap(2, inc, L) [[2, 3], [4, 5, 6]]

(n, func, seq)

Source from the content-addressed store, hash-verified

301
302
303def ndeepmap(n, func, seq):
304 """Call a function on every element within a nested container
305
306 >>> def inc(x):
307 ... return x + 1
308 >>> L = [[1, 2], [3, 4, 5]]
309 >>> ndeepmap(2, inc, L)
310 [[2, 3], [4, 5, 6]]
311 """
312 if n == 1:
313 return [func(item) for item in seq]
314 elif n > 1:
315 return [ndeepmap(n - 1, func, item) for item in seq]
316 elif isinstance(seq, list):
317 return func(seq[0])
318 else:
319 return func(seq)
320
321
322def import_required(mod_name, error_msg):

Callers 3

test_ndeepmapFunction · 0.90
to_delayedMethod · 0.90
homogeneous_deepmapFunction · 0.85

Calls 1

funcFunction · 0.50

Tested by 1

test_ndeepmapFunction · 0.72