Решение на Пет функции от Гергана Петрова

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

Към профила на Гергана Петрова

Резултати

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

Код

import string
from collections import defaultdict
from functools import cmp_to_key
ALPHABET = set('абвгдежзийклмнопрстуфхцчшщъьюя')
def is_cyrillic_letter(x):
return x in ALPHABET
def is_pangram(sentence):
return set(filter(is_cyrillic_letter, sentence.lower())) == ALPHABET
def char_histogram(text):
return {char: text.count(char) for char in text}
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(dictionary):
result = defaultdict(dict)
for key, value in dictionary.items():
result[type(key)].update({key: value})
return result
def is_letter(x):
return x not in (string.punctuation + string.whitespace)
def is_anagram(word1, word2):
word1 = sorted(filter(is_letter, word1.lower()))
word2 = sorted(filter(is_letter, word2.lower()))
return word1 == word2
def word_anagrams(word, words):
return list(filter(lambda x: is_anagram(x, word), words))
def anagrams(words):
return list(map(lambda x: word_anagrams(x, words), words))

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

................
----------------------------------------------------------------------
Ran 16 tests in 0.011s

OK

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

Гергана обнови решението на 13.03.2014 20:49 (преди над 10 години)

+import string
+from collections import defaultdict
+from functools import cmp_to_key
+
+ALPHABET = set('абвгдежзийклмнопрстуфхцчшщъьюя')
+
+
+def is_letter(x):
+ return x not in (string.punctuation + string.whitespace)
+
+
+def is_pangram(sentence):
+ return set(filter(is_letter, sentence.lower())) == ALPHABET
+
+
+def char_histogram(text):
+ keys = [char for char in text]
+ values = [text.count(key) for key in keys]
+ return dict(zip(keys, values))
+
+
+def sort_by(func, arguments):
+ return sorted(arguments, key=cmp_to_key(func))
+
+
+def group_by_type(dictionary):
+ result = defaultdict(dict)
+ for key, value in dictionary.items():
+ result[type(key)].update({key: value})
+ return result
+
+
+def is_anagram(word1, word2):
+ return sorted(word1) == sorted(word2)
+
+
+def word_anagrams(word, words):
+ return list(filter((lambda x: is_anagram(x, word)), words))
+
+
+def anagrams(words):
+ return list(map((lambda x: word_anagrams(x, words)), words))

Гергана обнови решението на 15.03.2014 23:21 (преди над 10 години)

-import string
from collections import defaultdict
from functools import cmp_to_key
ALPHABET = set('абвгдежзийклмнопрстуфхцчшщъьюя')
-def is_letter(x):
- return x not in (string.punctuation + string.whitespace)
+def is_cyrillic_letter(x):
+ return x in ALPHABET
def is_pangram(sentence):
- return set(filter(is_letter, sentence.lower())) == ALPHABET
+ return set(filter(is_cyrillic_letter, sentence.lower())) == ALPHABET
def char_histogram(text):
- keys = [char for char in text]
- values = [text.count(key) for key in keys]
- return dict(zip(keys, values))
+ return {char: text.count(char) for char in text }
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(dictionary):
result = defaultdict(dict)
for key, value in dictionary.items():
result[type(key)].update({key: value})
return result
def is_anagram(word1, word2):
- return sorted(word1) == sorted(word2)
+ return sorted(word1.lower()) == sorted(word2.lower())
def word_anagrams(word, words):
- return list(filter((lambda x: is_anagram(x, word)), words))
+ return list(filter(lambda x: is_anagram(x, word), words))
def anagrams(words):
- return list(map((lambda x: word_anagrams(x, words)), words))
+ return list(map(lambda x: word_anagrams(x, words), words))

Гергана обнови решението на 15.03.2014 23:22 (преди над 10 години)

from collections import defaultdict
from functools import cmp_to_key
ALPHABET = set('абвгдежзийклмнопрстуфхцчшщъьюя')
def is_cyrillic_letter(x):
return x in ALPHABET
def is_pangram(sentence):
return set(filter(is_cyrillic_letter, sentence.lower())) == ALPHABET
def char_histogram(text):
- return {char: text.count(char) for char in text }
+ return {char: text.count(char) for char in text}
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(dictionary):
result = defaultdict(dict)
for key, value in dictionary.items():
result[type(key)].update({key: value})
return result
def is_anagram(word1, word2):
return sorted(word1.lower()) == sorted(word2.lower())
def word_anagrams(word, words):
return list(filter(lambda x: is_anagram(x, word), words))
def anagrams(words):
return list(map(lambda x: word_anagrams(x, words), words))

Гергана обнови решението на 16.03.2014 18:56 (преди над 10 години)

+import string
from collections import defaultdict
from functools import cmp_to_key
ALPHABET = set('абвгдежзийклмнопрстуфхцчшщъьюя')
def is_cyrillic_letter(x):
return x in ALPHABET
def is_pangram(sentence):
return set(filter(is_cyrillic_letter, sentence.lower())) == ALPHABET
def char_histogram(text):
return {char: text.count(char) for char in text}
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(dictionary):
result = defaultdict(dict)
for key, value in dictionary.items():
result[type(key)].update({key: value})
return result
+def is_letter(x):
+ return x not in (string.punctuation + string.whitespace)
+
+
def is_anagram(word1, word2):
- return sorted(word1.lower()) == sorted(word2.lower())
+ word1 = sorted(filter(is_letter, word1.lower()))
+ word2 = sorted(filter(is_letter, word2.lower()))
+ return word1 == word2
def word_anagrams(word, words):
return list(filter(lambda x: is_anagram(x, word), words))
def anagrams(words):
return list(map(lambda x: word_anagrams(x, words), words))