app/soc/logic/dicts.py
changeset 1749 a0ae6e6431a9
parent 1370 8d684e64fbbe
child 1842 391b89d04bdd
--- a/app/soc/logic/dicts.py	Sun Mar 08 15:00:08 2009 +0000
+++ b/app/soc/logic/dicts.py	Sun Mar 08 15:00:31 2009 +0000
@@ -197,3 +197,13 @@
     result[key_value].append(value)
 
   return result
+
+def groupDictBy(target, key, new_key=None):
+  """Groups a dictionary by a key.
+  """
+
+  if not new_key:
+    new_key = key
+
+  result = ((k, v[new_key]) for k, v in target.iteritems() if v[key])
+  return dict(result)