Search code examples
pythonjsondictionarydata-analysis

Merge Dicts in List calculating min, max and average in Python


I try to write a World of Warcraft Auctionhouse analyzing tool.
For each auction i have data that looks like this:

{
 'timeLeftHash': 4, 
 'bid': 3345887, 
 'timestamp': 1415339912, 
 'auc': 1438188059, 
 'quantity': 1, 
 'id': 309774, 
 'ownerHash': 751, 
 'buy': 3717652, 
 'ownerRealmHash': 1, 
 'item': 35965
}

I'd like to combine all dicts that have the same value of "item" so i can get a minBuy, avgBuy, maxBuy, minQuantity, avgQuantity, maxQantity and the sum of combined auctions for the specific item.

How can i archieve that?

I already tried to write it in a Second list of dicts, but then the min and max is missing...


Solution

  • You could try to make a dictionary where the key is the item ID and the Value is a list of tuples of price and quantity.

    If you would like to keep all the information, you could also make a dictionary where the key is the item ID and the value is a list of dictionaries corresponding to that ID and from there extract the info that you want through a generator.