#apply different reduce-fun at every lvl of hierarchy #! on firt call len(lol) must be > 2 def deep_reduce(funs, LoL): def isi(a): return isinstance(a, (list,tuple,types.GeneratorType)) #or is_iter(a) def calc(a,b): # print('--=', funs[0],a,b) a1 = deep_reduce(funs[1:], a) if isi(a) else a b1 = deep_reduce(funs[1:], b) if isi(b) else b return funs[0](a1,b1) if isi(LoL): return reduce(calc,LoL) else: return LoL