Решение на Пет функции от Моника Димитрова

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

Към профила на Моника Димитрова

Резултати

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

Код

import string
import functools
def is_pangram(sentence):
alphabet = set('абвгдежзийклмнопрстуфхцчшщъьюя')
return set(sentence.lower()) >= alphabet
def char_histogram(text):
histogram = dict()
for symbol in text:
histogram[symbol] = text.count(symbol)
return histogram
def sort_by(func, arguments):
return sorted(arguments, key=functools.cmp_to_key(func))
def group_by_type(dictionary):
grouped = dict()
for (key, value) in zip(dictionary.keys(), dictionary.values()):
if type(key) in grouped:
grouped[type(key)][key] = value
else:
grouped[type(key)] = {key: value}
return grouped
def is_anagram(word, other_word):
return sorted(word) == sorted(other_word)
def anagrams(words):
return []

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

FFFF............
======================================================================
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-99dgnd/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({'astronomer', 'moonstarer'})
frozenset({'ramy', 'mary', 'army'})
frozenset({'debit card', 'bad credit'})
frozenset({'bau'})

======================================================================
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-99dgnd/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'})

======================================================================
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-99dgnd/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({"So I'm cuter", 'Tom Cruise'})
frozenset({'Tom Marvolo Riddle', 'I am Lord Voldemort'})

======================================================================
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-99dgnd/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({'кавалер', 'акварел'})

----------------------------------------------------------------------
Ran 16 tests in 0.015s

FAILED (failures=4)

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

Моника обнови решението на 19.03.2014 16:21 (преди около 10 години)

+import string
+import functools
+
+def is_pangram(sentence):
+ alphabet = set('абвгдежзийклмнопрстуфхцчшщъьюя')
+ return set(sentence.lower()) >= alphabet
+
+def char_histogram(text):
+ histogram = dict()
+ for symbol in text:
+ histogram[symbol] = text.count(symbol)
+ return histogram
+
+def sort_by(func, arguments):
+ return sorted(arguments, key=functools.cmp_to_key(func))
+
+def group_by_type(dictionary):
+ grouped = dict()
+ for (key, value) in zip(dictionary.keys(), dictionary.values()):
+ if type(key) in grouped:
+ grouped[type(key)][key] = value
+ else:
+ grouped[type(key)] = {key: value}
+ return grouped
+
+def is_anagram(word, other_word):
+ return sorted(word) == sorted(other_word)
+
+def anagrams(words):
+ return []