Решение на Пет функции от Милен Христов

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

Към профила на Милен Христов

Резултати

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

Код

def is_pangram(input_entry):
bul_alphabet = [chr(char) for char in range(1072, 1104)]
bul_alphabet.remove(chr(1099))
bul_alphabet.remove(chr(1101))
for letter in input_entry:
if letter.isupper() and letter.lower() in bul_alphabet:
bul_alphabet.remove(letter.lower())
if letter in bul_alphabet:
bul_alphabet.remove(letter)
if len(bul_alphabet) > 0:
return False
return True
def char_histogram(input_entry):
input_list = list(input_entry)
dictionary = dict([(x, input_list.count(x)) for x in set(input_list)])
return dictionary
def sort_by(func, arguments):
for x in range(0, len(arguments)):
for y in range(x, len(arguments)):
if func(arguments[x], arguments[y]) > 0:
arguments[x], arguments[y] = arguments[y], arguments[x]
return arguments
def group_by_type(dictionary):
di = {}
list_as_tuples = dictionary.items()
for x in dictionary:
di[type(x)] = {first: second for first, second in list_as_tuples
if type(first) == type(x)}
return di
def anagrams(words):
table = {}
for item in words:
word_sorted = ' '.join(sorted(item.lower()))
if word_sorted in table:
table[word_sorted].append(item)
else:
table[word_sorted] = []
table[word_sorted].append(item)
return [second for first, second in table.items()]

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

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

======================================================================
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-f6lypc/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: Lists differ: [0, 2, 4, 1, 3, 5] != [0, 2, 4, 3, 1, 5]

First differing element 3:
1
3

- [0, 2, 4, 1, 3, 5]
?              ---

+ [0, 2, 4, 3, 1, 5]
?           +++


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

FAILED (failures=2)

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

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

+def is_pangram(input_entry):
+ bul_alphabet = [chr(char) for char in range(1072, 1104)]
+ bul_alphabet.remove(chr(1099))
+ bul_alphabet.remove(chr(1101))
+ for letter in input_entry:
+ if letter.isupper() and letter.lower() in bul_alphabet:
+ bul_alphabet.remove(letter.lower())
+ if letter in bul_alphabet:
+ bul_alphabet.remove(letter)
+ if len(bul_alphabet) > 0:
+ return False
+ return True
+
+
+def char_histogram(input_entry):
+ input_list = list(input_entry)
+ dictionary = dict([(x, input_list.count(x)) for x in set(input_list)])
+ return dictionary
+
+
+def sort_by(func, arguments):
+ for x in range(0, len(arguments)):
+ for y in range(x, len(arguments)):
+ if func(arguments[x], arguments[y]) > 0:
+ arguments[x], arguments[y] = arguments[y], arguments[x]
+ return arguments
+
+
+def group_by_type(dictionary):
+ di = {}
+ list_as_tuples = dictionary.items()
+ for x in dictionary:
+ di[type(x)] = {first: second for first, second in list_as_tuples
+ if type(first) == type(x)}
+ return di
+
+
+def anagrams(words):
+ table = {}
+ for item in words:
+ word_sorted = ' '.join(sorted(item.lower()))
+ if word_sorted in table:
+ table[word_sorted].append(item)
+ else:
+ table[word_sorted] = []
+ table[word_sorted].append(item)
+
+ return [second for first, second in table.items()]