Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. data = {'Account balances': [{'2008-04-04': 252216},
  2. {'2010-05-17': 3619948},
  3. {'2010-10-25': 590954},
  4. {'2014-10-01': 568340},
  5. {'2016-09-04': 2424784},
  6. {'2018-08-25': 261463}],
  7. 'Address book contacts': [{'2017-12-05': 20580060}],
  8. 'Age groups': [{'2014-02-17': 37784}, {'2017-12-31': 84011}],
  9. 'Ages': [{'2014-09-01': 1287073}],
  10. 'Apps installed on devices': [{'2017-12-05': 20580060}],
  11. 'Astrological signs': [{'2016-02-29': 27393015}],
  12. 'Audio recordings': [{'2018-08-16': 44109}],
  13. 'Auth tokens': [{'2016-08-07': 2247314}, {'2019-01-03': 17204697}],
  14. 'Avatars': [{'2016-02-21': 144989},
  15. {'2016-02-29': 1535473},
  16. {'2016-05-18': 1531235},
  17. {'2016-05-28': 97151},
  18. {'2017-11-28': 512311}],
  19. 'Bank account numbers': [{'2015-07-01': 88678}, {'2018-10-21': 242715}],
  20. 'Beauty ratings': [{'2015-11-11': 1100089}],
  21. 'Biometric data': [{'2016-03-27': 228605}],
  22. 'Bios': [{'2018-02-28': 19611022}],
  23. 'Browser user agent details': [{'2008-04-04': 252216},
  24. {'2013-01-04': 179967},
  25. {'2016-05-20': 104977},
  26. {'2016-12-15': 400260},
  27. {'2018-07-09': 1279263},
  28. {'2018-08-24': 411755},
  29. {'2018-12-28': 7633234}],}
  30.  
  31.  
  32. for key, value in data.items():
  33. total = sum(v for row in value for k, v in row.items())
  34. print(key, total) # Or add to new data structure?
  35.  
  36. from copy import deepcopy
  37.  
  38. data_copy = deepcopy(data)
  39.  
  40. for key in data_copy:
  41. list_of_dicts = data_copy[key]
  42. list_of_tuples = [list(dct.items())[0] for dct in list_of_dicts]
  43. new_dict = dict(list_of_tuples)
  44. data_copy[key] = new_dict
  45.  
  46. print(data_copy)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement