one problem statement on python list arithmetic that is I have one list say,
my_set = [24565,24621,32,598,899]
I want to take difference between first two elements and if difference is in range of -127 to 127 then add +128 to next index position and so on. First element of the list stays as-is
Like this the output
[24565, 56, +128, 24589, +128, −566, +128, -301].
this is what I tried to do
def inRange(val):
return val in range(-127,127)
my_set = [24565,24621,32,598,899]
for i in range(len(my_set)-1):
res = my_set[i] - my_set[i+1]
if inRange(res) == True:
my_set.insert(i+1,res)
my_set.insert(i+2,128)
print(my_set)
Please tell me how to do that.?? THankyou!