I want to turn the following for loop:
n = 10
x0 = 0
values = [x0]
for i in range(n):
x0 = f(x0)
values.append(x0)
into a one liner. I figured I could do something like this:
values = [f(x0) for i in range(n)]
but I need to update the value of x0 in each instance of the loop. Any ideas?
Walrus operator
:=to the rescue: