Решение на Четири функции от Весела Бандова

Обратно към всички решения

Към профила на Весела Бандова

Резултати

  • 4 точки от тестове
  • 0 бонус точки
  • 4 точки общо
  • 13 успешни тест(а)
  • 7 неуспешни тест(а)

Код

def groupby(func, sec):
return {func(y): [x for x in sec if func(x) == func(y)] for y in sec}
def zip_with(func, *iterables):
a = min(map(lambda x: len(x), iterables))
for i in range(a):
b = (list(map(lambda x: x[i], iterables)))
yield func(*b)
def generator():
i = 0
while True:
yield i
i = i+1
def helper(idx, func):
a = lambda x: x
while idx > 0:
a = (lambda f: lambda x: func(f(x)))(a)
idx = idx-1
return a
def iterate(func):
return (helper(y, func) for y in generator())

Лог от изпълнението

EEEEE..........EE...
======================================================================
ERROR: test_cache_cache_is_not_global (test.SecondHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20130408-29081-e5qvvl/test.py", line 129, in test_cache_cache_is_not_global
    cached_double1 = solution.cache(double, 3)
AttributeError: 'module' object has no attribute 'cache'

======================================================================
ERROR: test_cache_call_is_cached (test.SecondHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20130408-29081-e5qvvl/test.py", line 116, in test_cache_call_is_cached
    cached_double = solution.cache(double, 10)
AttributeError: 'module' object has no attribute 'cache'

======================================================================
ERROR: test_cache_function_with_vargs (test.SecondHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20130408-29081-e5qvvl/test.py", line 159, in test_cache_function_with_vargs
    cached_sum = solution.cache(sum_varargs, 10)
AttributeError: 'module' object has no attribute 'cache'

======================================================================
ERROR: test_cache_no_cache (test.SecondHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20130408-29081-e5qvvl/test.py", line 103, in test_cache_no_cache
    cached_double = solution.cache(double, 0)
AttributeError: 'module' object has no attribute 'cache'

======================================================================
ERROR: test_cache_size_is_respected (test.SecondHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20130408-29081-e5qvvl/test.py", line 143, in test_cache_size_is_respected
    cached_double = solution.cache(double, 2)
AttributeError: 'module' object has no attribute 'cache'

======================================================================
ERROR: test_zip_with_empty (test.SecondHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20130408-29081-e5qvvl/test.py", line 67, in test_zip_with_empty
    self.assertEqual(expected, list(actual))
  File "/tmp/d20130408-29081-e5qvvl/solution.py", line 8, in zip_with
    a = min(map(lambda x: len(x), iterables))
ValueError: min() arg is an empty sequence

======================================================================
ERROR: test_zip_with_infinite_sequence (test.SecondHomeworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20130408-29081-e5qvvl/test.py", line 82, in test_zip_with_infinite_sequence
    self.assertEqual(expected, list(actual))
  File "/tmp/d20130408-29081-e5qvvl/solution.py", line 8, in zip_with
    a = min(map(lambda x: len(x), iterables))
  File "/tmp/d20130408-29081-e5qvvl/solution.py", line 8, in <lambda>
    a = min(map(lambda x: len(x), iterables))
TypeError: object of type 'itertools.repeat' has no len()

----------------------------------------------------------------------
Ran 20 tests in 0.012s

FAILED (errors=7)

История (1 версия и 0 коментара)

Весела обнови решението на 15.03.2013 23:02 (преди над 11 години)

+
+
+def groupby(func, sec):
+ return {func(y): [x for x in sec if func(x) == func(y)] for y in sec}
+
+
+def zip_with(func, *iterables):
+ a = min(map(lambda x: len(x), iterables))
+ for i in range(a):
+ b = (list(map(lambda x: x[i], iterables)))
+ yield func(*b)
+
+
+def generator():
+ i = 0
+ while True:
+ yield i
+ i = i+1
+
+
+def helper(idx, func):
+ a = lambda x: x
+ while idx > 0:
+ a = (lambda f: lambda x: func(f(x)))(a)
+ idx = idx-1
+ return a
+
+
+def iterate(func):
+ return (helper(y, func) for y in generator())