app/soc/logic/dicts.py
changeset 1370 8d684e64fbbe
parent 1308 35b75ffcbb37
child 1749 a0ae6e6431a9
equal deleted inserted replaced
1369:0be1f471413c 1370:8d684e64fbbe
   179 
   179 
   180     # Update the result for the next iteration
   180     # Update the result for the next iteration
   181     result = tmpresult
   181     result = tmpresult
   182 
   182 
   183   return result
   183   return result
       
   184 
       
   185 def groupby(target, group_key):
       
   186   """Groups a list of dictionaries by group_key.
       
   187   """
       
   188 
       
   189   result = {}
       
   190 
       
   191   for value in target:
       
   192     key_value = value[group_key]
       
   193 
       
   194     if not key_value in result:
       
   195       result[key_value] = []
       
   196 
       
   197     result[key_value].append(value)
       
   198 
       
   199   return result