I have a list x with values:
[0.09086322 -0.66400483 -0.85750224, ... 73.92927078, 5.18024081, -17.12200886]
Here, I want to copy values in the range (-50, 50) from list x to another list y.
I have tried implementing the following code, but it doesn’t seem to work
y = []
for i in x:
if x[i] >= -50 and x[i] <=50:
y.append(x[i])
I get the following error:
only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and
integer or boolean arrays are valid indices
>Solution :
x = [0.09086322,-0.66400483,-0.85750224,73.92927078,55.18024081,-17.12200886]
y = []
for i in range(len(x)):
if x[i]>= -50.0 and x[i] <=50.0:
y.append(x[i])
print(y)