I'm trying to use a for loop in order to modify values in a list, based on values on a second list. Hence I though that the "zip" function would come in handy, however I'm not getting the result I'm expecting. See an example here:
list_a = [0,0,0,0]
list_b = [1,2,3,4]
for a, b in zip(list_a, list_b):
a = b*2
I though that this modifies list_a, however it does not. My understanding was that, inside the loop, "a" was first equal to list_a[0], then list_a[1], etc, in other words views of the list.
I have actually 2 questions:
a) what are "a" and "b" inside the loop, if they are not views of the two lists?
b) is there a pythonic way of implementing this loop (i.e. something different from looping over i in range(len(list_a))?
a=..does not modifya[0]. It just assigns a new value to the variable.viewis a numpy array concept, not a list one.list_a[i]returns the object contained by that index in the list.a = list_a[0]makes the nameareference some object, that happens to be the first element oflist_a, but that object has no knowledge of that