Десислава обнови решението на 14.03.2013 22:31 (преди над 11 години)
+from collections import defaultdict
+
+def groupby(func,seq):
+ res = defaultdict(list)
+ [res[func(x)].append(x) for x in seq]
+ return res
+
+import functools
+
+def iterate(func):
+ key = lambda x: x
+ while True :
+ yield key
+ key = functools.partial(lambda f,*args: func(f(*args)), key)
+
+import itertools
+
+def zip_with(func, *iterables):
+ iterators = list(map(iter,iterables))
+ return [func(*tuple([next(iterator) for iterator in iterators])) for i in range(min(map(len,list(iterables))))]
+
+from collections import OrderedDict
+
+def cache(func , cache_size):
+ def func_cached(x , d = OrderedDict()):
+ if x not in d.keys():
+ if len(d) >= cache_size :
+ d.popitem(False)
+ d[x] = func(x)
+ return d[x]
+ return lambda x: func_cached(x)
Ужасен код. Казахме ви да наблегнете на стила.
80417.py:3:1: E302 expected 2 blank lines, found 1
80417.py:3:17: E231 missing whitespace after ','
80417.py:10:1: E302 expected 2 blank lines, found 1
80417.py:12:15: E203 whitespace before ':'
80417.py:14:41: E231 missing whitespace after ','
80417.py:15:1: W293 blank line contains whitespace
80417.py:18:1: E302 expected 2 blank lines, found 1
80417.py:19:30: E231 missing whitespace after ','
80417.py:20:80: E501 line too long (115 > 79 characters)
80417.py:20:96: E231 missing whitespace after ','
80417.py:24:1: E302 expected 2 blank lines, found 1
80417.py:24:15: E203 whitespace before ','
80417.py:25:22: E203 whitespace before ','
80417.py:25:26: E251 unexpected spaces around keyword / parameter equals
80417.py:25:28: E251 unexpected spaces around keyword / parameter equals
80417.py:31:36: E203 whitespace before ':'