Решение на Пет функции от Иван Бобев

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

Към профила на Иван Бобев

Резултати

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

Код

from collections import defaultdict
from functools import cmp_to_key
BG_LETTERS = "абвгдежзийклмнопрстуфхцчшщъьюя"
def is_pangram(sentence):
return len({letter for letter in sentence.lower()
if letter in BG_LETTERS}) == 30
def char_histogram(text):
histogram = defaultdict(int)
for character in text:
histogram[character] += 1
return histogram
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(dictionary):
type_dict = defaultdict(dict)
for key, value in dictionary.items():
type_dict[type(key)][key] = value
return type_dict
def anagrams(words):
sorted_words = [''.join(sorted(word)) for word in
(filter(lambda c: c.isalpha(), w.lower()) for w in words)]
result = defaultdict(list)
for i in range(len(words)):
result[sorted_words[i]].append(words[i])
return list(result.values())

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

................
----------------------------------------------------------------------
Ran 16 tests in 0.008s

OK

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

Иван обнови решението на 13.03.2014 01:01 (преди над 10 години)

+from collections import defaultdict
+from functools import cmp_to_key
+
+BG_LETTERS = "абвгдежзийклмнопрстуфхцчшщъьюя"
+
+
+def is_pangram(sentence):
+ return len({letter for letter in sentence.lower()
+ if letter in BG_LETTERS}) == 30
+
+
+def char_histogram(text):
+ histogram = defaultdict(int)
+ for character in text:
+ histogram[character] += 1
+ return histogram
+
+
+def sort_by(func, arguments):
+ return sorted(arguments, key=cmp_to_key(func))
+
+
+def group_by_type(dictionary):
+ type_dict = defaultdict(dict)
+ for key, value in dictionary.items():
+ type_dict[type(key)][key] = value
+ return type_dict
+
+
+def anagrams(words):
+ sorted_words = [''.join(sorted(word)) for word in words]
+ result = defaultdict(list)
+ for i in range(len(words)):
+ result[sorted_words[i]].append(words[i])
+ return result.values()

Иван обнови решението на 13.03.2014 01:21 (преди над 10 години)

from collections import defaultdict
from functools import cmp_to_key
BG_LETTERS = "абвгдежзийклмнопрстуфхцчшщъьюя"
def is_pangram(sentence):
return len({letter for letter in sentence.lower()
if letter in BG_LETTERS}) == 30
def char_histogram(text):
histogram = defaultdict(int)
for character in text:
histogram[character] += 1
return histogram
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(dictionary):
type_dict = defaultdict(dict)
for key, value in dictionary.items():
type_dict[type(key)][key] = value
return type_dict
def anagrams(words):
sorted_words = [''.join(sorted(word)) for word in words]
result = defaultdict(list)
for i in range(len(words)):
result[sorted_words[i]].append(words[i])
- return result.values()
+ return list(result.values())

Иван обнови решението на 16.03.2014 10:20 (преди над 10 години)

from collections import defaultdict
from functools import cmp_to_key
BG_LETTERS = "абвгдежзийклмнопрстуфхцчшщъьюя"
def is_pangram(sentence):
return len({letter for letter in sentence.lower()
if letter in BG_LETTERS}) == 30
def char_histogram(text):
histogram = defaultdict(int)
for character in text:
histogram[character] += 1
return histogram
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(dictionary):
type_dict = defaultdict(dict)
for key, value in dictionary.items():
type_dict[type(key)][key] = value
return type_dict
def anagrams(words):
- sorted_words = [''.join(sorted(word)) for word in words]
+ sorted_words = [''.join(sorted(word)) for word in
+ (filter(lambda c: c.isalpha(), w.lower()) for w in words)]
result = defaultdict(list)
for i in range(len(words)):
result[sorted_words[i]].append(words[i])
return list(result.values())