Added format and containsAll to the dicts module
authorSverre Rabbelier <srabbelier@gmail.com>
Mon, 16 Mar 2009 23:51:20 +0000
changeset 1899 c841800f3727
parent 1898 7f18e83a129f
child 1900 a2966f072219
Added format and containsAll to the dicts module Patch by: Sverre Rabbelier
app/soc/logic/dicts.py
--- a/app/soc/logic/dicts.py	Mon Mar 16 21:18:20 2009 +0000
+++ b/app/soc/logic/dicts.py	Mon Mar 16 23:51:20 2009 +0000
@@ -182,6 +182,7 @@
 
   return result
 
+
 def groupby(target, group_key):
   """Groups a list of dictionaries by group_key.
   """
@@ -198,6 +199,7 @@
 
   return result
 
+
 def groupDictBy(target, key, new_key=None):
   """Groups a dictionary by a key.
   """
@@ -208,9 +210,26 @@
   result = ((k, v[new_key]) for k, v in target.iteritems() if v[key])
   return dict(result)
 
+
 def identity(target):
   """Returns a dictionary with the values equal to the keys.
   """
 
-  result = [(i, i) for i in target]
+  result = ((i, i) for i in target)
   return dict(result)
+
+
+def format(target, input):
+  """Returns a dictionary with the values formatted with input.
+  """
+
+  result = ((k, v % input) for k, v in target.iteritems())
+  return dict(result)
+
+
+def containsAll(target, keys):
+  """Returns true iff target contains all keys.
+  """
+
+  result = ((i in target) for i in keys)
+  return all(result)