Решение на Пет функции от Антон Стоянов

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

Към профила на Антон Стоянов

Резултати

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

Код

#!/usr/bin/python
#-*- coding: cp1251 -*-
from _functools import cmp_to_key
def is_pangram(sentence):
input_set = set(sentence.lower())
the_bulgarian_alphabet = set('абвгдежзийклмнопрстуфхцчшщъьюя')
intersected_set = input_set.intersection(the_bulgarian_alphabet)
return len(intersected_set) is len(the_bulgarian_alphabet)
def char_histogram(text):
histogram_dict = {x : 0 for x in set(text)}
for x in list(text):
histogram_dict[x] = histogram_dict[x]+1
return histogram_dict
def sort_by(func, arguments):
arguments.sort(key=cmp_to_key(func))
return arguments
def group_by_type(dictionary):
typed_dict = {}
for x in dictionary.keys():
if type(x) in typed_dict.keys():
typed_dict[type(x)].update({x:dictionary[x]})
else:
typed_dict[type(x)] = {x:dictionary[x]}
return typed_dict
def anagrams(words):
return words

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

FFFF........F...
======================================================================
FAIL: 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-v6soxl/test.py", line 109, in test_list_of_latin_anagrams
    set(map(frozenset, solution.anagrams(words))))
AssertionError: Items in the first set but not the second:
frozenset({'debit card', 'bad credit'})
frozenset({'army', 'mary', 'ramy'})
frozenset({'moonstarer', 'astronomer'})
frozenset({'bau'})
Items in the second set but not the first:
frozenset({'t', 's', 'r', 'o', 'n', 'm', 'e', 'a'})
frozenset({'t', 'r', 'i', 'e', 'd', 'c', 'b', 'a', ' '})
frozenset({'u', 'b', 'a'})
frozenset({'y', 'm', 'r', 'a'})

======================================================================
FAIL: 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-v6soxl/test.py", line 125, in test_with_different_cases
    set(map(frozenset, solution.anagrams(words))))
AssertionError: Items in the first set but not the second:
frozenset({'Dave Barry', 'Ray Adverb'})
Items in the second set but not the first:
frozenset({'y', 'v', 'R', 'r', 'a', 'e', 'd', 'b', 'A', ' '})
frozenset({'y', 'v', 'r', 'e', 'D', 'B', 'a', ' '})

======================================================================
FAIL: 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-v6soxl/test.py", line 135, in test_with_different_symbols
    set(map(frozenset, solution.anagrams(words))))
AssertionError: Items in the first set but not the second:
frozenset({'Tom Marvolo Riddle', 'I am Lord Voldemort'})
frozenset({'Tom Cruise', "So I'm cuter"})
Items in the second set but not the first:
frozenset({'R', 'v', 'T', 'M', 'r', 'o', 'm', 'l', 'i', 'e', 'd', 'a', ' '})
frozenset({'u', 'T', 's', 'r', 'o', 'm', 'i', 'e', 'C', ' '})
frozenset({'l', 'V', 't', 'r', 'o', 'm', 'L', 'I', 'e', 'd', 'a', ' '})
frozenset({'u', 't', 'S', 'r', 'o', 'm', 'I', "'", 'e', 'c', ' '})

======================================================================
FAIL: 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-v6soxl/test.py", line 117, in test_with_list_of_cyrilic_anagrams
    set(map(frozenset, solution.anagrams(words))))
AssertionError: Items in the first set but not the second:
frozenset({'кавалер', 'акварел'})
Items in the second set but not the first:
frozenset({'л', 'к', 'е', 'в', 'а', 'р'})

======================================================================
FAIL: test_with_pangrams (test.TestIsPangram)
----------------------------------------------------------------------
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-v6soxl/test.py", line 12, in test_with_pangrams
    'Ах, чудна българска земьо, полюшвай цъфтящи жита!'))
AssertionError: False is not true

----------------------------------------------------------------------
Ran 16 tests in 0.017s

FAILED (failures=5)

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

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

+#!/usr/bin/python
+#-*- coding: cp1251 -*-
+
+from _functools import cmp_to_key
+
+def is_pangram(sentence):
+ input_set = set(sentence.lower())
+ the_bulgarian_alphabet = set('абвгдежзийклмнопрстуфхцчшщъьюя')
+ intersected_set = input_set.intersection(the_bulgarian_alphabet)
+ return len(intersected_set) is len(the_bulgarian_alphabet)
+
+def char_histogram(text):
+ histogram_dict = {x : 0 for x in set(text)}
+ for x in list(text):
+ histogram_dict[x] = histogram_dict[x]+1
+ return histogram_dict
+
+
+def sort_by(func, arguments):
+ arguments.sort(key=cmp_to_key(func))
+ return arguments
+
+def group_by_type(dictionary):
+ typed_dict = {}
+ for x in dictionary.keys():
+ if type(x) in typed_dict.keys():
+ typed_dict[type(x)].update({x:dictionary[x]})
+ else:
+ typed_dict[type(x)] = {x:dictionary[x]}
+ return typed_dict
+
+def anagrams(words):
+ return words