From 74c0697127ab0cb4948cad1dafe141294e6366d2 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Tue, 17 Mar 2015 16:21:57 +0100 Subject: [PATCH 3/4] utils: add a helper function to convert a dictionnary of list into a dictionnary of sets It helps for comparing dictionnaries of values, for example with LDAP. --- src/authentic2/utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/authentic2/utils.py b/src/authentic2/utils.py index e10a045..74266e0 100644 --- a/src/authentic2/utils.py +++ b/src/authentic2/utils.py @@ -448,8 +448,12 @@ def batch(iterable, size): sourceiter = iter(iterable) while True: batchiter = islice(sourceiter, size) yield chain([batchiter.next()], batchiter) def lower_keys(d): '''Convert all keys in dictionary d to lowercase''' return dict((key.lower(), value) for key, value in d.iteritems()) + +def to_dict_of_set(d): + '''Convert a dictionary of sequence into a dictionary of sets''' + return dict((k, set(v)) for k, v in d.iteritems()) -- 1.9.1