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

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

Към профила на Весела Бандова

Резултати

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

Код

from functools import reduce
import string
def is_pangram(sentence):
cyrillic_alphabet = "абвгдежзийклмнопрстуфхцчшщъьюя"
array_sentence = list(set(sentence.lower()))
return cyrillic_alphabet in "".join(sorted(array_sentence))
def char_histogram(text):
return {x: len([a for a in text if a == x]) for x in text}
def sort_by(func, arguments):
sorted_list = []
for i in range(0, len(arguments)):
minimal = reduce(lambda x, y: x if func(x, y) < 0 else y, arguments)
sorted_list.append(minimal)
arguments.remove(minimal)
return sorted_list
def group_by_type(dictionary):
return {type(i): {d: dictionary[d] for d in dictionary
if type(d) == type(i)} for i in dictionary}
def fix_word(word):
letters = "абвгдежзийклмнопрстуфхцчшщъьюя" + string.ascii_lowercase
return "".join(sorted([i for i in word.lower() if i in letters]))
def anagrams(words):
fixed_words = [fix_word(x) for x in words]
return [[x for x in words if i == fix_word(x)] for i in set(fixed_words)]

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

...............F
======================================================================
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-1d3rvti/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] != [4, 2, 0, 5, 3, 1]

First differing element 0:
0
4

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

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

FAILED (failures=1)

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

Весела обнови решението на 19.03.2014 13:37 (преди над 10 години)

+from functools import reduce
+import string
+
+
+def is_pangram(sentence):
+ cyrillic_alphabet = "абвгдежзийклмнопрстуфхцчшщъьюя"
+ array_sentence = list(set(sentence.lower()))
+ return cyrillic_alphabet in "".join(sorted(array_sentence))
+
+
+def char_histogram(text):
+ return {x: len([a for a in text if a == x]) for x in text}
+
+
+def sort_by(func, arguments):
+ sorted_list = []
+ for i in range(0, len(arguments)):
+ minimal = reduce(lambda x, y: x if func(x, y) < 0 else y, arguments)
+ sorted_list.append(minimal)
+ arguments.remove(minimal)
+ return sorted_list
+
+
+def group_by_type(dictionary):
+ return {type(i): {d: dictionary[d] for d in dictionary
+ if type(d) == type(i)} for i in dictionary}
+
+
+def fix_word(word):
+ letters = "абвгдежзийклмнопрстуфхцчшщъьюя" + string.ascii_lowercase
+ return "".join(sorted([i for i in word.lower() if i in letters]))
+
+
+def anagrams(words):
+ fixed_words = [fix_word(x) for x in words]
+ return [[x for x in words if i == fix_word(x)] for i in set(fixed_words)]