Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Apr 10th, 2020 132 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. queryset = [{'a': 1, 'b': 2, 'c': 3, 'value': 1488}, {'a': 4, 'b': 5, 'c': 6, 'value': 500}]
  2. group_by_objs = ['a', 'b', 'c']
  3.  
  4. def make_nested_dict(d, l):
  5.     if len(l) == 0:
  6.         return {'date': d['value']}
  7.     else:
  8.         return {d[l[0]]: make_nested_dict(d, l[1:])}
  9.  
  10.  
  11. def join_dicts(ds):
  12.     if len(ds) == 0:
  13.         return {}
  14.     else:
  15.         return {**ds[0], **join_dicts(ds[1:])}
  16.  
  17.  
  18. def group_queryset(queryset, groups):
  19.     if len(queryset) == 0:
  20.         return []
  21.     else:
  22.         return [make_nested_dict(queryset[0], groups), *group_queryset(queryset[1:], groups)]
  23.  
  24.  
  25. result = join_dicts(group_queryset(queryset, group_by_objs))
  26.  
  27. print(result)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top