Commits

Roma Sokolov committed 4deeeac

principal realization of service

Comments (0)

Files changed (1)

+# -*- coding:utf-8 -*-
+
+# principal algorhytm of work
+
+from collections import defaultdict
+from itertools import chain
+
+STORAGE = defaultdict(set)
+
+def add(item, *tags):
+    for tag in tags:
+        STORAGE[tag].add(item)
+
+def get(*tags):
+    if tags:
+        return set(chain(*(cont for (tag, cont) in
+                           STORAGE.iteritems() if tag in tags)))
+    else:
+        return set(chain(*STORAGE.values()))
+
+def clean():
+    global STORAGE
+    STORAGE = defaultdict(set)
+
+def test():
+    add('x', '42')
+    add('y', '42', '23')
+    add('z', '23')
+    assert 'x' in get('42')
+    assert 'x' in get('42')
+    assert 'z' not in get('42')
+    assert 'z' in get('23')
+    assert 'y' in get('42', '23')