Today get the interesting result when creating a new solution for the task by list comprehension.
def checkio(array: list) -> int:
if array:
return sum([x for x in array if array.index(x) % 2 == 0]) * array[-1]
else:
return 0
assert checkio([0, 1, 2, 3, 4, 5]) == 30, "(0+2+4)*5=30"
assert checkio([1, 3, 5]) == 30, "(1+5)*5=30"
assert checkio([6]) == 36, "(6)*6=36"
assert checkio([]) == 0, "An empty array = 0"
assert checkio([-37,-36,-19,-99,29,20,3,-7,-64,84,36,62,26,-76,55,-24,84,49,-65,41]) == 1968
When I decided to do debugging I have seen that the sixteenth element was skipped. Why? On the Internet, I didn't find describe this cause.