Решение на Пет функции от Александър Наджарян

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

Към профила на Александър Наджарян

Резултати

  • 10 точки от тестове
  • 0 бонус точки
  • 10 точки общо
  • 16 успешни тест(а)
  • 0 неуспешни тест(а)

Код

import functools
def is_pangram(sentence):
cyrillic_alphabet = "абвгдежзийклмнопрстуфхцчшщъьюя"
for letter in cyrillic_alphabet:
if letter not in sentence and letter.upper() not in sentence:
return False
return True
def char_histogram(text):
return {symbol: text.count(symbol) for symbol in text}
def sort_by(func, arguments):
return sorted(arguments, key=functools.cmp_to_key(func))
def group_by_type(argument):
return {type(i): {j: argument[j] for j in argument if type(i) == type(j)}
for i in argument}
def only_letters(word):
return "".join(letter.lower() for letter in word if letter.isalpha())
def is_anagram(word, anagram):
return sorted(only_letters(anagram)) == sorted(only_letters(word))
def anagrams(words):
sorted_anagram = []
remembering_anagrams = []
for word in words:
if sorted(only_letters(word)) not in remembering_anagrams:
remembering_anagrams.append(sorted(only_letters(word)))
sorted_anagram.append([anagram for anagram in words
if is_anagram(word, anagram)])
return sorted_anagram

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

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

OK

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

Александър обнови решението на 19.03.2014 13:56 (преди над 10 години)

+import functools
+
+
+def is_pangram(sentence):
+ cyrillic_alphabet = "абвгдежзийклмнопрстуфхцчшщъьюя"
+
+ for letter in cyrillic_alphabet:
+ if letter not in sentence and letter.upper() not in sentence:
+ return False
+ return True
+
+
+def char_histogram(text):
+ return {symbol: text.count(symbol) for symbol in text}
+
+
+def sort_by(func, arguments):
+ return sorted(arguments, key=functools.cmp_to_key(func))
+
+
+def group_by_type(argument):
+ return {type(i): {j: argument[j] for j in argument if type(i) == type(j)}
+ for i in argument}
+
+
+def only_letters(word):
+ return "".join(letter.lower() for letter in word if letter.isalpha())
+
+
+def is_anagram(word, anagram):
+ return sorted(only_letters(anagram)) == sorted(only_letters(word))
+
+
+def anagrams(words):
+
+ sorted_anagram = []
+ remembering_anagrams = []
+
+ for word in words:
+ if sorted(only_letters(word)) not in remembering_anagrams:
+ remembering_anagrams.append(sorted(only_letters(word)))
+ sorted_anagram.append([anagram for anagram in words
+ if is_anagram(word, anagram)])
+
+ return sorted_anagram