0

Count sum of numbers in a list. Hello there, this afternoon i wanna show you how to count sum of numbers in a list.

There basicly to add it. In this script, i have some numbers like a money, and adding it to big string """...""". however, making a split() to split some money, and then create one function to looping that numbers to count it.

>>> a = """
... 12.500
... 11.000
... 26.500
... 11.500
... 13.000
... 13.500
... 11.500
... """
>>> def sum_list(list):
...     tmp = 0
...     for i in list:
...       tmp = tmp + int(i)
...     return tmp
... 
>>> b = a.replace(".","").split("n")[1:-1]
>>> sum_list(b)
99500
>>>
beginner python

Your Answer

blog comments powered by Disqus