Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To create a list [c1, f1(c1), f1^2(c1),...f1^(e1)(c1),.....fn^(en)(cn)] one can use itertools.accumulate() and itertools.chain() like:

import itertools

c = [2,3,4]
e = [5,4,3]
f = lambda x: x^2
list( itertools.chain( *[itertools.accumulate(range(ei), func=lambda x,y: f(x), initial=ci) for ci, ei in zip(c,e)] ) )

The above code iteratively apply function f squaring ei times to ci for each i, and produces the list [2, 4, 16, 256, 65536, 4294967296, 3, 9, 81, 6561, 43046721, 4, 16, 256, 65536].

To create a list [c1, f1(c1), f1^2(c1),...f1^(e1)(c1),.....fn^(en)(cn)] one can use itertools.accumulate() and itertools.chain() like:

import itertools

c = [2,3,4]
e = [5,4,3]
f = lambda x: x^2
list( itertools.chain( *[itertools.accumulate(range(ei), func=lambda x,y: f(x), initial=ci) for ci, ei in zip(c,e)] ) )

The above code iteratively apply applies a given function f squaring (squaring) ei times to ci for each i, from lists [5,4,3] and [2,3,4] respectively, and produces the list list:

[2, 4, 16, 256, 65536, 4294967296, 3, 9, 81, 6561, 43046721, 4, 16, 256, 65536].

To create a list [c1, f1(c1), f1^2(c1),...f1^(e1)(c1),.....fn^(en)(cn)] one can use itertools.accumulate() and itertools.chain() like:

import itertools

c = [2,3,4]
e = [5,4,3]
f = lambda x: x^2
list( itertools.chain( *[itertools.accumulate(range(ei), func=lambda x,y: f(x), initial=ci) for ci, ei in zip(c,e)] ) )

The above code iteratively applies a given function f (squaring) ei times to ci from concurrently running through lists [5,4,3] and [2,3,4] respectively, and produces the list:

[2, 4, 16, 256, 65536, 4294967296, 3, 9, 81, 6561, 43046721, 4, 16, 256, 65536].

To create a list [c1, f1(c1), f1^2(c1),...f1^(e1)(c1),.....fn^(en)(cn)] one can use itertools.accumulate() and itertools.chain() like:

import itertools

c = [2,3,4]
e = [5,4,3]
f = [lambda x: x^2, lambda x: x^2
2*x, lambda x: x+100]
list( itertools.chain( *[itertools.accumulate(range(ei), func=lambda x,y: f(x), fi(x), initial=ci) for ci, ei ei, fi in zip(c,e)] zip(c,e,f)] ) )

The above code iteratively applies a given function functions ffi (squaring) ei times to ci, where fi, ei, ci are concurrently running through lists [x^2, 2*x, x+100], [5,4,3] and [2,3,4] respectively, and produces the list:

[2, 102, 202, 302, 402, 502, 3, 103, 203, 303, 403, 4, 16, 256, 65536, 4294967296, 3, 9, 81, 6561, 43046721, 4, 16, 256, 65536]104, 204, 304].

To create a list [c1, f1(c1), f1^2(c1),...f1^(e1)(c1),.....fn^(en)(cn)] one can use itertools.accumulate() and itertools.chain() like:

import itertools

c = [2,3,4]
e = [5,4,3]
f = [lambda x: x^2, lambda x: 2*x, lambda x: x+100]
list( itertools.chain( *[itertools.accumulate(range(ei), sum( (list(itertools.accumulate(range(ei), func=lambda x,y: x,_: fi(x), initial=ci) initial=ci)) for ci, ei, fi ci,ei,fi in zip(c,e,f)] ) zip(c,e,f)), [] )

The above code iteratively applies given functions fi ei times to ci, where fi, ei, ci are concurrently running through lists [x^2, 2*x, x+100], [5,4,3] and [2,3,4] respectively, and produces the list:

[2, 102, 202, 302, 402, 502, 4, 16, 256, 65536, 4294967296, 3, 103, 203, 303, 403, 6, 12, 24, 48, 4, 104, 204, 304].

To create a list [c1, f1(c1), f1^2(c1),...f1^(e1)(c1),.....fn^(en)(cn)] one can use itertools.accumulate() and itertools.chain() like:

import itertools

c = [2,3,4]
e = [5,4,3]
f = [lambda x: x^2, lambda x: 2*x, lambda x: x+100]
sum( (list(itertools.accumulate(range(ei), func=lambda x,_: fi(x), initial=ci)) for ci,ei,fi in zip(c,e,f)), [] )

The above code iteratively applies given functions fi ei times to ci, where fi, ei, ci are concurrently running through lists [x^2, 2*x, x+100], [5,4,3] and [2,3,4] respectively, and produces the list:

[2, 4, 16, 256, 65536, 4294967296, 3, 6, 12, 24, 48, 4, 104, 204, 304].

To create a list [c1, f1(c1), f1^2(c1),...f1^(e1)(c1),.....fn^(en)(cn)] one can use itertools.accumulate() and itertools.chain.from_iterable() like:

import itertools

c = [2,3,4]
e = [5,4,3]
f = [lambda x: x^2, lambda x: 2*x, lambda x: x+100]
sum( (list(itertools.accumulate(range(ei), list( itertools.chain.from_iterable( itertools.accumulate(range(ei), func=lambda x,_: fi(x), initial=ci)) initial=ci) for ci,ei,fi in zip(c,e,f)), [] )
zip(c,e,f) ))

The above code iteratively applies given functions fi ei times to ci, where fi, ei, ci are concurrently running through the lists [x^2, 2*x, x+100], [5,4,3] and [2,3,4] respectively, and produces the list:

[2, 4, 16, 256, 65536, 4294967296, 3, 6, 12, 24, 48, 4, 104, 204, 304].