如何使用python 3获取列表项列表中所有list [1]的总和?

I am trying to get the sum of x in this type of list: myList=[[y,x],[y,x],[y,x]

这是我一直在尝试的代码:

myLists = [['0.9999', '2423.99000000'], ['0.9998', '900.00000000'], ['0.9997', '4741.23000000'], ['0.9995', '6516.16000000'], ['0.9991', '10.01000000'], ['0.9990', '9800.00000000']]
if chckList(myLists):
    floatList = []
    listLength = len(acceptibleBids)

    acceptibleBids0 = list(map(float, acceptibleBids[0]))
    acceptibleBids1 = list(map(float, acceptibleBids[1]))

    floatList.append(acceptibleBids0)
    floatList.append(acceptibleBids1)

    sumAmounts = sum(amount[1] for amount in floatList)
    print(sumAmounts)
    print(acceptibleBids)

我遇到了很多问题,但是下面列出了我当前的问题: 1.此列表是我接收它的方式,因此我一直试图将它们都更改为浮点数,以便我可以在myList中获取每个列表的sum(myList [1])。 2.列表范围从1到100

评论
yquo
yquo

将执行以下操作:

>>> sum([float(x[0]) for x in myLists])
5.997
点赞
评论