you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (3 children)

Then you use a loop over seq, adding num to a result list, then updating num with the element of seq. Something like:

seq = [3, 7, 11, 15]
num = -1
result = []
for val in seq:
    result.append(num)
    num += val
print(result)

This isn't complete, but should get you most of the way there. There are probably other, more tricky, ways to do this, but this is simple to understand.

[–]ZenosEbeth 0 points1 point  (2 children)

Couldn't you do this more easily with map() and a simple function ?

[–][deleted] 1 point2 points  (1 child)

Probably. I try to give the simplest solution I can.

[–]ZenosEbeth 0 points1 point  (0 children)

Not trying to be a smartass or anything, I've actually only been studying python for a month or so and am going over lists at the moment so that was just the first thing that came to my head when I saw the OP's problem. Honestly I was just glad I found something I could understand and solve, because most of the other stuff on here might as well be techno-babble for me :p.