Skip to content Skip to sidebar Skip to footer

Python Dictionary Of List Of List Aggregate

I have timeseries dictionary available, I need to count all the values of each keys, what's the most efficient way to do this? DATA = {u'604': [[1361836800, {u'14885549': 52, u'9

Solution 1:

Using sum() with a generator:

total = sum(sum(inner[1].values()) for outer in DATA.values() for inner in outer)

This is equivalent in behavior to the following for loop:

total = 0
for outer in DATA.values():
    for inner in outer:
        total += sum(inner[1].values())

Post a Comment for "Python Dictionary Of List Of List Aggregate"