In a homework set I\'m working on, I\'ve come across the following question, which I am having trouble answering in a Python-3 function:
\"Write a fun
def alternate(l):
return sum(l[::2]) - sum(l[1::2])
Take the sum of all the even indexed elements and subtract the sum of all the odd indexed elements. Empty lists sum to 0
so it coincidently handles lists of length 0 or 1 without code specifically for those cases.
References: