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

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

Към профила на Мариан Ламбовски

Резултати

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

Код

alphabet = ('а', 'б', 'в', 'г', 'д', 'е',
'ж', 'з', 'и', 'й', 'к', 'л',
'м', 'н', 'о', 'п', 'р', 'с',
'т', 'у', 'ф', 'х', 'ц', 'ч',
'ш', 'щ', 'ъ', 'ь', 'ю', 'я')
def is_pangram(sentence):
for letter in alphabet:
if letter not in sentence:
return False
return True
def char_histogram(text):
symbols_dict = {}
for symbol in text:
symbols_dict[symbol] = text.count(symbol)
return symbols_dict
def sort_by(func, arguments):
for i in range(len(arguments)-1):
for j in range(len(arguments)-1):
if func(arguments[j],arguments[j+1]) > 0:
arguments[j],arguments[j+1] = arguments[j+1],arguments[j]
return arguments
def group_by_type(dictionary):
group_dict = {}
keys_list = dictionary.keys()
for key in keys_list:
temp_dict = {}
typeof_item = type(key)
for id, item in dictionary.items():
if type(id) == typeof_item:
temp_dict[id] = item
group_dict[typeof_item] = temp_dict
return group_dict
def anagrams(words):
anagrams_list = []
checked_words = []
for i in range(len(words)):
temp_list = []
character_count = char_histogram(words[i])
for j in range(len(words)):
if character_count == char_histogram(words[j]):
temp_list.append(words[j])
if character_count not in checked_words:
anagrams_list.append(temp_list)
checked_words.append(character_count)
return anagrams_list

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

.FF.........F...
======================================================================
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-7ao0jb/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({'Ray Adverb'})
frozenset({'Dave Barry'})

======================================================================
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-7ao0jb/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({"So I'm cuter", 'Tom Cruise'})
Items in the second set but not the first:
frozenset({'I am Lord Voldemort'})
frozenset({'Tom Marvolo Riddle'})
frozenset({"So I'm cuter"})
frozenset({'Tom Cruise'})

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

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

FAILED (failures=3)

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

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

+alphabet = ('а', 'б', 'в', 'г', 'д', 'е',
+ 'ж', 'з', 'и', 'й', 'к', 'л',
+ 'м', 'н', 'о', 'п', 'р', 'с',
+ 'т', 'у', 'ф', 'х', 'ц', 'ч',
+ 'ш', 'щ', 'ъ', 'ь', 'ю', 'я')
+
+def is_pangram(sentence):
+ for letter in alphabet:
+ if letter not in sentence:
+ return False
+ return True
+
+def char_histogram(text):
+ symbols_dict = {}
+ for symbol in text:
+ symbols_dict[symbol] = text.count(symbol)
+ return symbols_dict
+
+def sort_by(func, arguments):
+ for i in range(len(arguments)-1):
+ for j in range(len(arguments)-1):
+ if func(arguments[j],arguments[j+1]) > 0:
+ arguments[j],arguments[j+1] = arguments[j+1],arguments[j]
+ return arguments
+
+def group_by_type(dictionary):
+ group_dict = {}
+ keys_list = dictionary.keys()
+ for key in keys_list:
+ temp_dict = {}
+ typeof_item = type(key)
+ for id, item in dictionary.items():
+ if type(id) == typeof_item:
+ temp_dict[id] = item
+ group_dict[typeof_item] = temp_dict
+ return group_dict
+
+def anagrams(words):
+ anagrams_list = []
+ checked_words = []
+ for i in range(len(words)):
+ temp_list = []
+ character_count = char_histogram(words[i])
+ for j in range(len(words)):
+ if character_count == char_histogram(words[j]):
+ temp_list.append(words[j])
+ if character_count not in checked_words:
+ anagrams_list.append(temp_list)
+ checked_words.append(character_count)
+ return anagrams_list