python sum of last n items in list
test_list = [4, 5, 2, 6, 7, 8, 10]
K = 5
# Inverse K slice Sum using list slicing + sum()
res = sum(test_list[-K:])
print("The last K elements sum of list is : " + str(res))
# Result:
# The last K elements sum of list is : 33