An example of what I want to do:
What I want to do is have the first element equal itself, and every other equals itself minus the previous.
array = [12, 16, 31, 53, 70]
new = []
for x in range(5):
for value in array:
value -= array[x]
new.append(value)
#print new
#should be new = [12, 4, 15, 22, 17]
I'm running it in my interpreter and getting this:
[0, 4, 19, 41, 58, -4, 0, 15, 37, 54, -19, -15, 0, 22, 39, -41, -37, -22, 0, 17,
-58, -54, -39, -17, 0]
Is my code way off, any suggestions to get it working?
2006-07-05
16:30:15
·
2 answers
·
asked by
Anonymous
in
Programming & Design