I have a very big list of dictionaries and I want to sum the insides

2024/7/8 7:16:17

Something like

{A: 3, 45, 34, 4, 2, 5, 94, 2139, 230345, 283047, 230847}, {B: 92374, 324, 345, 345, 45879, 34857987, 3457938457), {C: 23874923874987, 2347}

How can I reduce that to

{A: 2304923094820398}, {B: 2374923784897}, {C: 29348239847239847}

Values obviously not exact. I just want to add up all the values in a non-time consuming manner.

Answer
d = [{'A': [3, 45, 34, 4, 2, 5, 94, 2139, 230345, 283047, 230847]}, {'B': [92374, 324, 345, 345, 45879, 34857987, 3457938457]}, {'C': [23874923874987, 2347]}]
[{x.keys()[0]:sum(x.values()[0])} for x in d]
https://en.xdnf.cn/q/120388.html

Related Q&A

How to debug a TypeError no attribute __getitem__? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 10 years ago.Improv…

Change character based off of its position? Python 2.7

I have a string on unknown length, contain the characters a-z A-Z 0-9. I need to change each character using their position from Left to Right using a dictionary.Example:string = "aaaaaaaa" d…

Changing type using str() and int()...how it works

If I do this, I get:>>> x = 1 >>> y = 2 >>> type(x) <class int> >>> type(y) <class str>That all makes sense to me, except that if I convert using:>>…

Caesar cypher in Python

I am new to python and I want to write a program that asks for a line of input (each number will be separated by a single space.) It would use a simple letter-number substitution cipher. Each letter w…

Flatten a list with sublists and strings [duplicate]

This question already has answers here:Flatten an irregular (arbitrarily nested) list of lists(54 answers)How do I make a flat list out of a list of lists?(32 answers)Closed 2 years ago.How can I flat…

Guitar string code in Python? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 1…

What is the point of initializing extensions with the flask instance in Flask? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 8 years ago.Improve…

Nested list doesnt work properly

import re def get_number(element):re_number = re.match("(\d+\.?\d*)", element)if re_number:return float(re_number.group(1))else:return 1.0def getvalues(equation):elements = re.findall("…

How can I increment array with loop?

Ive got two lists:listOne = [33.325556, 59.8149016457, 51.1289412359] listTwo = [2.5929778, 1.57945488999, 8.57262235411]I use len to tell me how many items are in my list:itemsInListOne = int(len(list…

Two Complements Python (with as least bits as possible)

I am trying to output the binary representation of an negative number with the least bytes available each time.Example:-3 -> 101 -10 -> 10110