Решение на Пет функции от Аделина Рудова

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

Към профила на Аделина Рудова

Резултати

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

Код

import functools
CYRILLIC_ALPHABET = "абвгдежзийклмнопрстуфхцчшщъьюя"
LATIN_ALPHABET = "abcdefghijklmnopqrstuvwxyz"
def is_pangram(sentence):
for character in CYRILLIC_ALPHABET:
if character not in sentence.lower():
return False
return True
def char_histogram(text):
return dict((character, text.count(character)) for character in text)
def sort_by(func, arguments):
return sorted(arguments, key=functools.cmp_to_key(func))
def group_by_type(dictionary):
return dict((type(key), get_subdicitonary(dictionary, type(key)))
for key in dictionary.keys())
def get_subdicitonary(dictionary, key_type):
return dict((key, dictionary[key]) for key in dictionary.keys()
if type(key) == key_type)
def anagrams(words):
result = []
grouped_words = [generate_anagrams_sublist(word, words) for word in words]
for anagrams_list in grouped_words:
if anagrams_list not in result:
result.append(anagrams_list)
return result
def is_anagram(word, compared_to):
for character in word:
if (character in LATIN_ALPHABET
and word.count(character) != compared_to.count(character)):
return False
return True
def generate_anagrams_sublist(word, words):
return ([anagram_word for anagram_word in words
if is_anagram(anagram_word, word)])

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

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

----------------------------------------------------------------------
Ran 16 tests in 0.010s

FAILED (failures=2)

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

Аделина обнови решението на 14.03.2014 18:01 (преди над 10 години)

+ALPHABET = "абвгдежзийклмнопрстуфхцчшщъьюя"
+
+def is_pangram(sentence):
+ for c in ALPHABET:
+ if c not in sentence.lower():
+ return False
+ return True
+
+def char_histogram(text):
+ return dict((c, text.count(c)) for c in text)
+
+def sort_by(func, arguments):
+ return []
+
+def group_by_type(dictionary):
+ return dict((type(key), get_subdicitonary(dictionary, type(key))) for key in dictionary.keys())
+
+def get_subdicitonary(dictionary, key_type):
+ return dict((key, dictionary[key]) for key in dictionary.keys() if type(key) == key_type)
+
+
+def anagrams(words):
+ return []

Това е все още draft, който написах набързо след работа и качих тук, за да не си го пращам на мейла и да мога да продължа да работя от друг компютър. Но благодаря за коментара - всичкото това съм го взела предвид още тогава. :)

Иначе би трябвало първата фунцкия да работи - поне с тестовете, написани до момента няма фейлнати такива.

Аделина обнови решението на 17.03.2014 10:37 (преди над 10 години)

ALPHABET = "абвгдежзийклмнопрстуфхцчшщъьюя"
def is_pangram(sentence):
for c in ALPHABET:
if c not in sentence.lower():
return False
- return True
+ return True
def char_histogram(text):
return dict((c, text.count(c)) for c in text)
def sort_by(func, arguments):
return []
def group_by_type(dictionary):
return dict((type(key), get_subdicitonary(dictionary, type(key))) for key in dictionary.keys())
def get_subdicitonary(dictionary, key_type):
return dict((key, dictionary[key]) for key in dictionary.keys() if type(key) == key_type)
def anagrams(words):
return []

Аделина обнови решението на 17.03.2014 12:11 (преди над 10 години)

ALPHABET = "абвгдежзийклмнопрстуфхцчшщъьюя"
+
def is_pangram(sentence):
- for c in ALPHABET:
- if c not in sentence.lower():
+ for character in ALPHABET:
+ if character not in sentence.lower():
return False
return True
+
def char_histogram(text):
- return dict((c, text.count(c)) for c in text)
+ return dict((character, text.count(character)) for character in text)
+
def sort_by(func, arguments):
return []
+
def group_by_type(dictionary):
- return dict((type(key), get_subdicitonary(dictionary, type(key))) for key in dictionary.keys())
+ return dict((type(key), get_subdicitonary(dictionary, type(key)))
+ for key in dictionary.keys())
+
def get_subdicitonary(dictionary, key_type):
- return dict((key, dictionary[key]) for key in dictionary.keys() if type(key) == key_type)
+ return dict((key, dictionary[key]) for key in dictionary.keys()
+ if type(key) == key_type)
def anagrams(words):
- return []
+ result = []
+ grouped_words = [generate_anagrams_subset(word, words) for word in words]
+ for anagrams_set in grouped_words:
+ if anagrams_set not in result:
+ result.append(anagrams_set)
+ return list(map(list, result))
+
+
+def is_anagram(word, compared_to):
+ for c in word:
+ if word.count(c) != compared_to.count(c):
+ return False
+ return True
+
+
+def generate_anagrams_subset(word, words):
+ return ({anagram_word for anagram_word in words
+ if is_anagram(anagram_word, word)})

Аделина обнови решението на 17.03.2014 12:17 (преди над 10 години)

ALPHABET = "абвгдежзийклмнопрстуфхцчшщъьюя"
def is_pangram(sentence):
for character in ALPHABET:
if character not in sentence.lower():
return False
return True
def char_histogram(text):
return dict((character, text.count(character)) for character in text)
def sort_by(func, arguments):
return []
def group_by_type(dictionary):
return dict((type(key), get_subdicitonary(dictionary, type(key)))
- for key in dictionary.keys())
+ for key in dictionary.keys())
def get_subdicitonary(dictionary, key_type):
return dict((key, dictionary[key]) for key in dictionary.keys()
- if type(key) == key_type)
+ if type(key) == key_type)
def anagrams(words):
result = []
grouped_words = [generate_anagrams_subset(word, words) for word in words]
for anagrams_set in grouped_words:
if anagrams_set not in result:
result.append(anagrams_set)
return list(map(list, result))
def is_anagram(word, compared_to):
for c in word:
if word.count(c) != compared_to.count(c):
return False
return True
def generate_anagrams_subset(word, words):
return ({anagram_word for anagram_word in words
- if is_anagram(anagram_word, word)})
+ if is_anagram(anagram_word, word)})

Аделина обнови решението на 17.03.2014 13:15 (преди над 10 години)

+import functools
+
ALPHABET = "абвгдежзийклмнопрстуфхцчшщъьюя"
def is_pangram(sentence):
for character in ALPHABET:
if character not in sentence.lower():
return False
return True
def char_histogram(text):
return dict((character, text.count(character)) for character in text)
def sort_by(func, arguments):
- return []
+ return sorted(arguments, key=functools.cmp_to_key(func))
def group_by_type(dictionary):
return dict((type(key), get_subdicitonary(dictionary, type(key)))
for key in dictionary.keys())
def get_subdicitonary(dictionary, key_type):
return dict((key, dictionary[key]) for key in dictionary.keys()
if type(key) == key_type)
def anagrams(words):
result = []
grouped_words = [generate_anagrams_subset(word, words) for word in words]
for anagrams_set in grouped_words:
if anagrams_set not in result:
result.append(anagrams_set)
return list(map(list, result))
def is_anagram(word, compared_to):
for c in word:
if word.count(c) != compared_to.count(c):
return False
return True
def generate_anagrams_subset(word, words):
return ({anagram_word for anagram_word in words
if is_anagram(anagram_word, word)})

Аделина обнови решението на 19.03.2014 09:57 (преди над 10 години)

import functools
+
ALPHABET = "абвгдежзийклмнопрстуфхцчшщъьюя"
def is_pangram(sentence):
for character in ALPHABET:
if character not in sentence.lower():
return False
return True
def char_histogram(text):
return dict((character, text.count(character)) for character in text)
def sort_by(func, arguments):
return sorted(arguments, key=functools.cmp_to_key(func))
def group_by_type(dictionary):
return dict((type(key), get_subdicitonary(dictionary, type(key)))
for key in dictionary.keys())
def get_subdicitonary(dictionary, key_type):
return dict((key, dictionary[key]) for key in dictionary.keys()
if type(key) == key_type)
def anagrams(words):
result = []
grouped_words = [generate_anagrams_subset(word, words) for word in words]
for anagrams_set in grouped_words:
if anagrams_set not in result:
result.append(anagrams_set)
return list(map(list, result))
def is_anagram(word, compared_to):
- for c in word:
- if word.count(c) != compared_to.count(c):
+ for character in word:
+ if word.count(character) != compared_to.count(character):
return False
return True
def generate_anagrams_subset(word, words):
return ({anagram_word for anagram_word in words
if is_anagram(anagram_word, word)})

Аделина обнови решението на 19.03.2014 15:44 (преди над 10 години)

import functools
-ALPHABET = "абвгдежзийклмнопрстуфхцчшщъьюя"
+CYRILLIC_ALPHABET = "абвгдежзийклмнопрстуфхцчшщъьюя"
+LATIN_ALPHABET = "abcdefghijklmnopqrstuvwxyz"
def is_pangram(sentence):
- for character in ALPHABET:
+ for character in CYRILLIC_ALPHABET:
if character not in sentence.lower():
return False
return True
def char_histogram(text):
return dict((character, text.count(character)) for character in text)
def sort_by(func, arguments):
return sorted(arguments, key=functools.cmp_to_key(func))
def group_by_type(dictionary):
return dict((type(key), get_subdicitonary(dictionary, type(key)))
for key in dictionary.keys())
def get_subdicitonary(dictionary, key_type):
return dict((key, dictionary[key]) for key in dictionary.keys()
if type(key) == key_type)
def anagrams(words):
result = []
- grouped_words = [generate_anagrams_subset(word, words) for word in words]
- for anagrams_set in grouped_words:
- if anagrams_set not in result:
- result.append(anagrams_set)
- return list(map(list, result))
+ grouped_words = [generate_anagrams_sublist(word, words) for word in words]
+ for anagrams_list in grouped_words:
+ if anagrams_list not in result:
+ result.append(anagrams_list)
+ return result
def is_anagram(word, compared_to):
for character in word:
- if word.count(character) != compared_to.count(character):
+ if (character in LATIN_ALPHABET
+ and word.count(character) != compared_to.count(character)):
return False
return True
-def generate_anagrams_subset(word, words):
- return ({anagram_word for anagram_word in words
+def generate_anagrams_sublist(word, words):
- if is_anagram(anagram_word, word)})
+ return ([anagram_word for anagram_word in words
+ if is_anagram(anagram_word, word)])