0

I have the below generator:

initial_state = [1, 1, 2, 3, 8]
length = 10


def nbonacci(initial_state_, seq_size_):
    initial_state_ = initial_state_
    for _ in range(seq_size_):
        initial_state_[0], initial_state_[-1] = initial_state_[-1], sum(initial_state_)
        yield initial_state_[-1]


print(initial_state + list(nbonacci(initial_state, length)))

However, if I concatenate the initial state of the list to what the generator has yielded, I can see that the initial_state has been modified by the generator, outputting this:

[1002, 1, 2, 3, 1625, 15, 29, 50, 85, 141, 232, 379, 617, 1002, 1625]

Is there any pythonic way to fetch the initial value of initial_state variable for displaying it afterwards and obtain the below output?

[1, 1, 2, 3, 8, 15, 29, 50, 85, 141, 232, 379, 617, 1002, 1625]
banana_99
  • 581
  • 2
  • 11

0 Answers0