Цанислава обнови решението на 15.03.2013 23:25 (преди над 11 години)
+from collections import OrderedDict
+
+
+def groupby(func, seq):
+ dictionary = {}
+ for element in seq:
+ dictionary.setdefault(func(element), []).append(element)
+ return OrderedDict(sorted(dictionary.items()))
+
+def compose(func1, func2):
+ def result(x):
+ return func1(func2(x))
+ return result
+
+def iterate(func):
+ result = lambda x: x
+ yield result
+ while True:
+ result = compose(func, result)
+ yield result
+
+def zip_with(func, *iterables):
+ for iterables in zip(*iterables):
+ yield func(*iterables)
+
+def cache(func, cache_size):
+ if cache_size == 0:
+ return func
+ cache = [(None, None)]*cache_size
+ def func_cached(argument):
+ for cache_element in cache:
+ if cache_element[0] == argument:
+ return cache_element[1]
+ cache.pop(0)
+ cache.append((argument, func(argument)))
+ return cache[cache_size-1][1]
+ return func_cached
31212.py:7:65: W291 trailing whitespace
31212.py:10:1: E302 expected 2 blank lines, found 1
31212.py:14:1: W293 blank line contains whitespace
31212.py:15:1: E302 expected 2 blank lines, found 1
31212.py:21:1: W293 blank line contains whitespace
31212.py:22:1: E302 expected 2 blank lines, found 1
31212.py:25:1: W293 blank line contains whitespace
31212.py:26:1: E302 expected 2 blank lines, found 1
31212.py:30:5: E301 expected 1 blank line, found 0