Решение на Пет функции от Атанас Пройчев

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

Към профила на Атанас Пройчев

Резултати

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

Код

def char_histogram(text):
histogram = {}
for char in text:
if histogram.__contains__(char):
histogram[char] += 1
else:
histogram[char] = 1
return histogram
ALPHABET = ('а', 'б', 'в', 'г', 'д', 'е', 'ж', 'з', 'и', 'й', 'к', 'л',
'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч',
'ш', 'щ', 'ъ', 'ь', 'ю', 'я')
def is_pangram(sentence):
histogram = char_histogram(sentence.lower())
for char in ALPHABET:
if not histogram.__contains__(char):
return False
return True
def anagrams(words):
pass
def group_by_type(dictionary):
pass
def sort_by(func, arguments):
pass

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

EEEE..FFFFF..FFF
======================================================================
ERROR: test_list_of_latin_anagrams (test.TestAnagrams)
----------------------------------------------------------------------
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/d20140319-21201-1skkqk9/test.py", line 109, in test_list_of_latin_anagrams
    set(map(frozenset, solution.anagrams(words))))
TypeError: 'NoneType' object is not iterable

======================================================================
ERROR: test_with_different_cases (test.TestAnagrams)
----------------------------------------------------------------------
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/d20140319-21201-1skkqk9/test.py", line 125, in test_with_different_cases
    set(map(frozenset, solution.anagrams(words))))
TypeError: 'NoneType' object is not iterable

======================================================================
ERROR: test_with_different_symbols (test.TestAnagrams)
----------------------------------------------------------------------
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/d20140319-21201-1skkqk9/test.py", line 135, in test_with_different_symbols
    set(map(frozenset, solution.anagrams(words))))
TypeError: 'NoneType' object is not iterable

======================================================================
ERROR: test_with_list_of_cyrilic_anagrams (test.TestAnagrams)
----------------------------------------------------------------------
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/d20140319-21201-1skkqk9/test.py", line 117, in test_with_list_of_cyrilic_anagrams
    set(map(frozenset, solution.anagrams(words))))
TypeError: 'NoneType' object is not iterable

======================================================================
FAIL: test_another_group_by_type (test.TestGroupByType)
----------------------------------------------------------------------
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/d20140319-21201-1skkqk9/test.py", line 74, in test_another_group_by_type
    solution.group_by_type({(1, 2): 12, ('a', 1): 1, 1: 'b', 'c': 15}))
AssertionError: {<class 'tuple'>: {(1, 2): 12, ('a', 1): 1}, <class 'int'>: {1: 'b'}, <class 'str'>: {'c': 15}} != None

======================================================================
FAIL: test_group_by_type (test.TestGroupByType)
----------------------------------------------------------------------
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/d20140319-21201-1skkqk9/test.py", line 68, in test_group_by_type
    solution.group_by_type({'a': 12, 'b': 1, 1: 'foo'}))
AssertionError: {<class 'int'>: {1: 'foo'}, <class 'str'>: {'b': 1, 'a': 12}} != None

======================================================================
FAIL: test_group_by_type_empty (test.TestGroupByType)
----------------------------------------------------------------------
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/d20140319-21201-1skkqk9/test.py", line 63, in test_group_by_type_empty
    self.assertEqual({}, solution.group_by_type({}))
AssertionError: {} != None

======================================================================
FAIL: test_group_by_type_with_frozen_set_key (test.TestGroupByType)
----------------------------------------------------------------------
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/d20140319-21201-1skkqk9/test.py", line 80, in test_group_by_type_with_frozen_set_key
    solution.group_by_type({(1, 2): 12, ('a', 1): 1, test_set: 15}))
AssertionError: {<class 'frozenset'>: {frozenset({1, 2, 3}): 15}, <class 'tuple'>: {(1, 2): 12, ('a', 1): 1}} != None

======================================================================
FAIL: test_group_by_type_with_functions (test.TestGroupByType)
----------------------------------------------------------------------
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/d20140319-21201-1skkqk9/test.py", line 93, in test_group_by_type_with_functions
    ('list', 'of', 'numbers'): [42, 73]
AssertionError: {<class 'function'>: {<function TestGroupByType.test_group_by_type_with_functions.<locals>.<lambda> at 0xb77e1d1c>: 'double'}, <class 'tuple'>: {('list', 'of', 'numbers'): [42, 73]}, <class 'str'>: {'three': 3}} != None

======================================================================
FAIL: test_sort_by_empty (test.TestSortBy)
----------------------------------------------------------------------
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/d20140319-21201-1skkqk9/test.py", line 44, in test_sort_by_empty
    self.assertEqual([], solution.sort_by(lambda x, y: x - y, []))
AssertionError: [] != None

======================================================================
FAIL: test_sort_by_one_element (test.TestSortBy)
----------------------------------------------------------------------
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/d20140319-21201-1skkqk9/test.py", line 57, in test_sort_by_one_element
    self.assertEqual([1], solution.sort_by(lambda x, y: x - y, [1]))
AssertionError: [1] != None

======================================================================
FAIL: test_sort_by_simple_test (test.TestSortBy)
----------------------------------------------------------------------
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/d20140319-21201-1skkqk9/test.py", line 54, in test_sort_by_simple_test
    solution.sort_by(lambda x, y: x % 2 - y % 2, [0, 1, 2, 3, 4, 5]))
AssertionError: [0, 2, 4, 1, 3, 5] != None

----------------------------------------------------------------------
Ran 16 tests in 0.012s

FAILED (failures=8, errors=4)

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

Атанас обнови решението на 19.03.2014 16:05 (преди над 10 години)

+def char_histogram(text):
+ histogram = {}
+ for char in text:
+ if histogram.__contains__(char):
+ histogram[char] += 1
+ else:
+ histogram[char] = 1
+
+ return histogram
+
+
+ALPHABET = ('а', 'б', 'в', 'г', 'д', 'е', 'ж', 'з', 'и', 'й', 'к', 'л',
+ 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч',
+ 'ш', 'щ', 'ъ', 'ь', 'ю', 'я')
+
+
+def is_pangram(sentence):
+ histogram = char_histogram(sentence.lower())
+ for char in ALPHABET:
+ if not histogram.__contains__(char):
+ return False
+
+ return True
+
+
+def anagrams(words):
+ pass
+
+
+def group_by_type(dictionary):
+ pass
+
+
+def sort_by(func, arguments):
+ pass