Симеон обнови решението на 13.03.2013 23:04 (преди над 11 години)
+def groupby(func, seq):
+ dict_result = {}
+ functionality_set = set(func(seq_element) for seq_element in seq)
+
+ for functionality_value in functionality_set:
+ dict_result[functionality_value] = [
+ seq_element for seq_element
+ in seq if func(seq_element) == functionality_value]
+ return dict_result
+
+
+def iterate(func):
+ func_iterator = lambda iterator: lambda x: func(iterator(x))
+ result_function = lambda x: x
+ yield result_function
+
+ while True:
+ result_function = func_iterator(f)
+ yield result_function
+
+
+def zip_with(func, *iterables):
+ for index_of_iterable in range(0, min([len(iterable)
+ for iterable in iterables])):
+ yield func(*[iterable[index_of_iterable] for iterable in iterables])
+
+
+def cache(func, cache_size):
+ memory = OrderedDict()
+
+ def func_cached(*args):
+ if cache_size < len(memory):
+ memory.popitem(0)
+ if args in memory:
+ return memory[args]
+ result = func(*args)
+ memory[args] = result
+ return result
+ return func_cached