[k for k in range (1,42) if k%2 != 0]
output: [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41]
Now, I want to make it to:
[-1, 3, -5, 7, -9, 11, -13, 15, -17, 19, -21, 23, -25, 27, -29, 31, -33, 35, -37, 39, -41]
So I tried:
def test(N):
k = []
for i in range (1,N+1):
if(i%2 != 0):
k.append(i)
for b in k[::2]: <--- it changes the value but doesn't update the list
b = -b
return k
test(43)
Any ideas or suggestions on how to approach this problem? Or the other question is, how could I traverse the even numbered index in the list while updating the element to a negative value