# HG changeset patch # User Sverre Rabbelier # Date 1237247480 0 # Node ID c841800f3727172b261e17d140579ea885fd4f18 # Parent 7f18e83a129f14fabdad8236a421df2ac0aff901 Added format and containsAll to the dicts module Patch by: Sverre Rabbelier diff -r 7f18e83a129f -r c841800f3727 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)