Answers for "python list total elements"

0

sum of elements in a list.

data = ['5', '4', '9']

sum(int(i) for i in data)
18
Posted by: Guest on November-27-2021
0

sum the contents of a list python

# Sum the contents of a list without the builtin sum function

list = [1,2,3,4,5]
sum = 0

# loop through each position of the list and 
# add the contents of each position to the variable, sum
for i in range(len(list)):
	sum += list[i]

# result is 1 + 2 + 3 + 4 + 5 = 15
print(sum)
Posted by: Guest on April-01-2021

Code answers related to "python list total elements"

Python Answers by Framework

Browse Popular Code Answers by Language