, , , reduce
( functools.reduce
Python 3):
>>> f = lambda x: (x >> 1) ^ (0x12*(x&1))
>>> x, n = 1, 5
>>> functools.reduce(lambda lst, _: lst + [f(lst[-1])], range(1, n), [x])
[1, 18, 9, 22, 11]
, , . , :
>>> functools.reduce(lambda lst, _: lst.append(f(lst[-1])) or lst, range(1, n), [x])
[1, 18, 9, 22, 11]
Or, as I already hinted in another answer, you can use itertools.accumulate
that much better, but still a little misuse, since it actually expects a binary function, whereas here we do not use either the second parameter or the actual iterable passed to the function, except for the very first value.
>>> list(itertools.accumulate([x] * n, lambda y, _: f(y)))
[1, 18, 9, 22, 11]