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

Function ndeepmap

dask/utils.py:302–318  ·  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

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