Summing elements in a list

前端 未结 7 741
我在风中等你
我在风中等你 2020-11-30 23:16

Here is my code, I need to sum an undefined number of elements in the list. How to do this?

l = raw_input()
l = l.split(\' \')
l.pop(0)

My

相关标签:
7条回答
  • 2020-12-01 00:14

    You can use map function and pythons inbuilt sum() function. It simplifies the solution. And reduces the complexity.
    a=map(int,raw_input().split())
    sum(a)
    Done!

    0 讨论(0)
提交回复
热议问题