Решение на Четири функции от Габриел Гатев

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

Към профила на Габриел Гатев

Резултати

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

Код

def groupby(func, seq):
result = {}
for x in seq:
result[func(x)] = [y for y in seq if func(y) == func(x)]
return result
def zip_with(func, *iterables):
zip_iterables = zip(*iterables)
while True:
yield func(*next(zip_iterables))
def iterate(func):
yield lambda x: x
for y in iterate(func):
yield lambda x: func(y(x))

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

EEEEE......FFF......
======================================================================
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-4nc96n/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-4nc96n/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-4nc96n/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-4nc96n/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-4nc96n/test.py", line 143, in test_cache_size_is_respected
    cached_double = solution.cache(double, 2)
AttributeError: 'module' object has no attribute 'cache'

======================================================================
FAIL: test_iterate_out_of_order_calls (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-4nc96n/test.py", line 54, in test_iterate_out_of_order_calls
    self.assertEqual(2 * 'ham', f1('ham'))
AssertionError: 'hamham' != 'hamhamhamhamhamhamhamham'
- hamham
+ hamhamhamhamhamhamhamham


======================================================================
FAIL: test_iterate_out_of_order_calls_again (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-4nc96n/test.py", line 54, in test_iterate_out_of_order_calls
    self.assertEqual(2 * 'ham', f1('ham'))
AssertionError: 'hamham' != 'hamhamhamhamhamhamhamham'
- hamham
+ hamhamhamhamhamhamhamham


======================================================================
FAIL: test_iterate_out_of_order_calls_yet_again (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-4nc96n/test.py", line 54, in test_iterate_out_of_order_calls
    self.assertEqual(2 * 'ham', f1('ham'))
AssertionError: 'hamham' != 'hamhamhamhamhamhamhamham'
- hamham
+ hamhamhamhamhamhamhamham


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

FAILED (failures=3, errors=5)

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

Габриел обнови решението на 15.03.2013 23:20 (преди около 11 години)

+def groupby(func, seq):
+ result = {}
+
+ for x in seq:
+ result[func(x)] = [y for y in seq if func(y) == func(x)]
+
+ return result
+
+
+def zip_with(func, *iterables):
+ zip_iterables = zip(*iterables)
+ while True:
+ yield func(*next(zip_iterables))
+
+
+def iterate(func):
+ yield lambda x: x
+ for y in iterate(func):
+ yield lambda x: func(y(x))