Решение на Четири функции от Рейхан Садък

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

Към профила на Рейхан Садък

Резултати

  • 3 точки от тестове
  • 1 отнета точка
  • 2 точки общо
  • 10 успешни тест(а)
  • 10 неуспешни тест(а)

Код

def groupby(func, seq):
return {func(i): list(j for j in seq if func(j) is func(i)) for i in seq}
def recApply(func, n):
if n > 1:
rec_func = recApply(func, n - 1)
return lambda x: func(rec_func(x))
return func
def iterate(func):
number_of_calls = 0
while True:
if number_of_calls is 0:
number_of_calls += 1
yield lambda x: x
else:
yield recApply(func, number_of_calls)
number_of_calls += 1

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

EEEEE..........EEEEE
======================================================================
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-4i54uj/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-4i54uj/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-4i54uj/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-4i54uj/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-4i54uj/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-4i54uj/test.py", line 66, in test_zip_with_empty
    actual = solution.zip_with(lambda x: x)
AttributeError: 'module' object has no attribute 'zip_with'

======================================================================
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-4i54uj/test.py", line 81, in test_zip_with_infinite_sequence
    actual = solution.zip_with(lambda x, y, z: x + y + z, first_names, spaces, last_names)
AttributeError: 'module' object has no attribute 'zip_with'

======================================================================
ERROR: test_zip_with_nonequalty (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-4i54uj/test.py", line 92, in test_zip_with_nonequalty
    actual = solution.zip_with(int.__add__, numbers1, numbers2)
AttributeError: 'module' object has no attribute 'zip_with'

======================================================================
ERROR: test_zip_with_one_shorter_seqence (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-4i54uj/test.py", line 73, in test_zip_with_one_shorter_seqence
    actual = solution.zip_with(str.__add__, first_names, last_names)
AttributeError: 'module' object has no attribute 'zip_with'

======================================================================
ERROR: test_zip_with_vargs_function (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-4i54uj/test.py", line 86, in test_zip_with_vargs_function
    actual = solution.zip_with(lambda *x: sum(x), [1], [2], [3], [5], [8])
AttributeError: 'module' object has no attribute 'zip_with'

----------------------------------------------------------------------
Ran 20 tests in 0.013s

FAILED (errors=10)

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

Рейхан обнови решението на 15.03.2013 21:57 (преди около 11 години)

+def groupby(func, seq):
+ return {func(i): list(j for j in seq if func(j) is func(i)) for i in seq}
+
+def recApply(func, n):
+ if n > 1:
+ rec_func = recApply(func, n - 1)
+ return lambda x: func(rec_func(x))
+ return func
+
+def iterate(func):
+ number_of_calls = 0
+ while True:
+ if number_of_calls is 0:
+ number_of_calls += 1
+ yield lambda x: x
+ else:
+ yield recApply(func, number_of_calls)
+ number_of_calls += 1