Николай обнови решението на 15.03.2013 16:13 (преди над 11 години)
+from collections import OrderedDict
+
+
+def groupby(func, seq):
+ result = {}
+ for element in seq:
+ key = func(element)
+ if key not in result.keys():
+ result[key] = [element]
+ else:
+ result[key].append(element)
+ return result
+
+
+def iterate(func):
+ pass
+
+
+def zip_with(func, *iterables):
+ return (func(*args) for args in zip(*iterables))
+
+
+def cache(func, cache_size):
+ store = OrderedDict()
+
+ def cached_function(x):
+ if x not in store:
+ if len(store) - 1 > cache_size:
+ store.popitem(last=False)
+ store[x] = func(x)
+ return store[x]
+ return cached_function