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

如何使用python 3获得列表项列表中所有列表[1]的总和?,python,python-3.x,Python,Python 3.x,我试图得到这类列表中x的总和: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(m

我试图得到这类列表中x的总和: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中找到每个列表的summyList[1]。 2.列表范围从1到100,以下操作即可:

>>> sum([float(x[0]) for x in myLists])
5.997
您可以使用列表理解:

这应该做到:

sum = 0
for pair in myLists:
    sum+= float(pair[1])

#of course, if there is something that can't
#be a float there, it'll raise an error, so
#do make all the checks you need to make
我不确定acceptibleBids在代码中来自何处,但我会假设它是myList的一个副本,或者类似的东西。代码的问题是acceptibleBids[0]只是['0.9999','2423.99000000']。同样,acceptibleBids[1]只是['0.9998','900.00000000']。所以当acceptibleBids[0]作为[[0.9999,2423.99000000]结束时而acceptibleBids1同样是错误的。这使得浮动列表不是您想要的


编辑:列表理解也很有效,但我有点喜欢这种方式。无论哪种方式,对于列表理解,这将是sum\u floats=sumfloat[pair[1]for pair in MyList]。

这非常适合我所做的工作!谢谢你,你帮了我很多忙:
sum = 0
for pair in myLists:
    sum+= float(pair[1])

#of course, if there is something that can't
#be a float there, it'll raise an error, so
#do make all the checks you need to make