Решение на Четири функции от Йордан Костадинов

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

Към профила на Йордан Костадинов

Резултати

  • 2 точки от тестове
  • 0 бонус точки
  • 2 точки общо
  • 5 успешни тест(а)
  • 15 неуспешни тест(а)

Код

def groupby(func, seq):
keys = {func(x) for x in seq}
groups = {key: [] for key in keys}
for item in seq:
groups[func(item)].append(item)
return groups
def iterate(func):
pass
def zip_with(func, *iterables):
pass
def cache(func, cache_size):
pass

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

EEEEE.....EEEEEEEEEE
======================================================================
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-1apn41h/test.py", line 131, in test_cache_cache_is_not_global
    self.assertEqual(42 * 2, cached_double1(42))
TypeError: 'NoneType' object is not callable

======================================================================
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-1apn41h/test.py", line 117, in test_cache_call_is_cached
    self.assertEqual(256, cached_double(128))
TypeError: 'NoneType' object is not callable

======================================================================
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-1apn41h/test.py", line 160, in test_cache_function_with_vargs
    self.assertEqual(6, cached_sum(1, 2, 3))
TypeError: 'NoneType' object is not callable

======================================================================
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-1apn41h/test.py", line 104, in test_cache_no_cache
    self.assertEqual(42 * 2, cached_double(42))
TypeError: 'NoneType' object is not callable

======================================================================
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-1apn41h/test.py", line 144, in test_cache_size_is_respected
    self.assertEqual(2, cached_double(1))
TypeError: 'NoneType' object is not callable

======================================================================
ERROR: test_iterate_ordered_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-1apn41h/test.py", line 38, in test_iterate_ordered_calls
    f = next(powers_of_two)
TypeError: 'NoneType' object is not an iterator

======================================================================
ERROR: 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-1apn41h/test.py", line 49, in test_iterate_out_of_order_calls
    f0 = next(powers_of_two)
TypeError: 'NoneType' object is not an iterator

======================================================================
ERROR: 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-1apn41h/test.py", line 49, in test_iterate_out_of_order_calls
    f0 = next(powers_of_two)
TypeError: 'NoneType' object is not an iterator

======================================================================
ERROR: 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-1apn41h/test.py", line 49, in test_iterate_out_of_order_calls
    f0 = next(powers_of_two)
TypeError: 'NoneType' object is not an iterator

======================================================================
ERROR: test_iterate_start_with_identity_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-1apn41h/test.py", line 33, in test_iterate_start_with_identity_function
    no_brackets = next(bracketisers)
TypeError: 'NoneType' object is not an iterator

======================================================================
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-1apn41h/test.py", line 67, in test_zip_with_empty
    self.assertEqual(expected, list(actual))
TypeError: 'NoneType' object is not iterable

======================================================================
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-1apn41h/test.py", line 82, in test_zip_with_infinite_sequence
    self.assertEqual(expected, list(actual))
TypeError: 'NoneType' object is not iterable

======================================================================
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-1apn41h/test.py", line 93, in test_zip_with_nonequalty
    self.assertNotEqual([3, 5, 8], list(actual))
TypeError: 'NoneType' object is not iterable

======================================================================
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-1apn41h/test.py", line 74, in test_zip_with_one_shorter_seqence
    self.assertEqual(expected, list(actual))
TypeError: 'NoneType' object is not iterable

======================================================================
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-1apn41h/test.py", line 87, in test_zip_with_vargs_function
    self.assertEqual(expected, list(actual))
TypeError: 'NoneType' object is not iterable

----------------------------------------------------------------------
Ran 20 tests in 0.014s

FAILED (errors=15)

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

Йордан обнови решението на 15.03.2013 22:22 (преди над 11 години)

+def groupby(func, seq):
+ keys = {func(x) for x in seq}
+ groups = {key: [] for key in keys}
+ for item in seq:
+ groups[func(item)].append(item)
+ return groups
+
+
+def iterate(func):
+ pass
+
+
+def zip_with(func, *iterables):
+ pass
+
+
+def cache(func, cache_size):
+ pass