I have a problem with correct initialization within a list
import random
a = [random.randint(0,1) for x in range(10)] # getting random 0 and 1
b = a[:] # copying 'a' list for purpose of analysis
for x,y in enumerate(b): # adding + 1 where value is 1
if y != 0:
b[x] += b[x-1]
print(a) # > [1, 0, 0, 1, 1, 1, 0, 0, 1, 1]
print(b) # > [2, 0, 0, 1, 2, 3, 0, 0, 1, 2]
# wanted # > [1, 0, 0, 1, 2, 3, 0, 0, 1, 2]
from a[1:] everything is ok. Python does correct initialization, however if a[0] == 1 and a[9] == 1, Python ofcourse takes a[9] as a start value in my case.
I am just asking if there is any pythonic way to solve this > explaining python to just start initialization from 0 at a[0] and passing a[9] as first value.
Thanks
if y!=0 and x!=0b[0-1]references the last item in the list, which could be a 1.