Answers for "sum of the number last 3 of list in python"

2

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
Posted by: Guest on July-12-2021

Code answers related to "sum of the number last 3 of list in python"

Python Answers by Framework

Browse Popular Code Answers by Language