我有一本字典,其中包含如下列表:a = {'Dairy-Milk': ['Dairy-Milk', '12345', '800', 1], 'test': ['test', '1111', '600', 1]}我想遍歷字典,對 (each_dictionary_Item[2] *each_dictionary_Item[3]) 執行乘法,然后獲取所有項目的總和。據我所知,我調用了 a.get_keys 然后我遍歷了鍵中的每個項目,并調用了 list pos 2 * 3,然后將其附加到另一個列表中,在其中我使用 sum(列表)....當添加新項目時,這會給我錯誤的總和。 for item in self.listofKeys: thequantity = self.productList[item][3] thecash = self.productList[item][2] multiplied = float(thequantity) * float(thecash) self.thesumsList.append(multiplied) self.ids.thetotal.text = "Total Payable: " + str(sum(self.thesumsList))有沒有更干凈的方法來實現我想要的?(獲取列表 list[3] * list[3] 中每個項目的總和)
獲取字典中每個列表中 2 個位置值的乘積之和
12345678_0001
2023-10-06 18:50:48