0

I have a list of objects (each containing 3 data members) and a list of collection names. Object members are: Collection name, Collection path, Bytes used.

I want to aggregate certain values (e.g. 'bytes used') based on two of the data members 'collection name' and 'collection path' (both string type) such that 'collection name' is present in list of collection names.

So the output must come like this:

Collection Name | Collection Path | Bytes

4

1 回答 1

0

您可能可以将 adefaultdict与键一起用作(名称,路径)的元组。就像是:

from collections import defaultdict
d = defaultdict(int)
for item in collection:
    d[(item.name, item.path)] += item.bytes
于 2013-07-08T07:56:36.913 回答