Apply function inside nested lists >>> inc = lambda x: x + 1 >>> deepmap(inc, [[1, 2], [3, 4]]) [[2, 3], [4, 5]] >>> add = lambda x, y: x + y >>> deepmap(add, [[1, 2], [3, 4]], [[10, 20], [30, 40]]) [[11, 22], [33, 44]]
(func, *seqs)
| 271 | |
| 272 | |
| 273 | def deepmap(func, *seqs): |
| 274 | """Apply function inside nested lists |
| 275 | |
| 276 | >>> inc = lambda x: x + 1 |
| 277 | >>> deepmap(inc, [[1, 2], [3, 4]]) |
| 278 | [[2, 3], [4, 5]] |
| 279 | |
| 280 | >>> add = lambda x, y: x + y |
| 281 | >>> deepmap(add, [[1, 2], [3, 4]], [[10, 20], [30, 40]]) |
| 282 | [[11, 22], [33, 44]] |
| 283 | """ |
| 284 | if isinstance(seqs[0], (list, Iterator)): |
| 285 | return [deepmap(func, *items) for items in zip(*seqs)] |
| 286 | else: |
| 287 | return func(*seqs) |
| 288 | |
| 289 | |
| 290 | @_deprecated() |
no test coverage detected
searching dependent graphs…