Aug-14-2018, 12:37 PM
HI,
I'm new to this so sorry if my formatting is a bit off!
Essentially I wish to have a list, say [1,2,3,4] and to loop through it, and sum the previous, current and next element.
When at the first element, in this case 1, i wish for the previous element to be the last in the list (4), so the sum is 4+1+2. I would also like to do this for the final element, so the sum would be 3+4+1. Is there a cleaner way to do this than a few if statements?
many thanks,
JY
I'm new to this so sorry if my formatting is a bit off!
Essentially I wish to have a list, say [1,2,3,4] and to loop through it, and sum the previous, current and next element.
When at the first element, in this case 1, i wish for the previous element to be the last in the list (4), so the sum is 4+1+2. I would also like to do this for the final element, so the sum would be 3+4+1. Is there a cleaner way to do this than a few if statements?
many thanks,
JY


