Решение на Пет функции от Данаил Койчев

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

Към профила на Данаил Койчев

Резултати

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

Код

import functools
CYRILLIC = 'абвгдежзийклмнопрстуфхцчшщъьюя'
def is_pangram(sentence):
return len([1 for char in CYRILLIC if char not in sentence.lower()]) == 0
def char_histogram(sentence):
hystogram = {}
for symbol in sentence:
hystogram[symbol] = hystogram.setdefault(symbol, 0) + 1
return hystogram
def sort_by(compare, args):
return sorted(args, key=functools.cmp_to_key(compare))
def group_by_type(dictionary):
type_dict = {}
for key in dictionary:
type_dict.setdefault(type(key), {})[key] = dictionary[key]
return type_dict
def anagrams(words):
groups = {}
for word in words:
letters = "".join(char for char in word.lower() if char.isalpha())
groups.setdefault(frozenset(char_histogram(letters)), []).append(word)
return [groups[group] for group in groups]

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

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

OK

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

Данаил обнови решението на 15.03.2014 03:17 (преди над 10 години)

+__cyrillic = 'абвгдежзийклмнопрстуфхцчшщъьюя'
+
+def is_pangram(sentence):
+ return not len([1 for char in __cyrillic if char not in sentence.lower()])
+
+def char_histogram(sentence):
+ hystogram = {}
+ for symbol in sentence:
+ hystogram[symbol] = hystogram.setdefault(symbol, 0) + 1
+ return hystogram
+
+def sort_by(compare, args):
+ for arg_number in range(0, len(args) - 1):
+ for bubble in range(0, len(args) - 1 - arg_number):
+ if compare(args[bubble], args[bubble + 1]) > 0:
+ args[bubble], args[bubble + 1] = args[bubble + 1], args[bubble]
+ return args
+
+def group_by_type(dictionary):
+ type_dict = {}
+ for key in dictionary:
+ type_dict.setdefault(type(key), {})[key] = dictionary[key]
+ return type_dict
+
+def anagrams(words):
+ groups = {}
+ for word in words:
+ groups.setdefault(frozenset(char_histogram(word).items()), []).append(word)
+ return [groups[group] for group in groups]

Данаил обнови решението на 15.03.2014 17:09 (преди над 10 години)

+import functools
__cyrillic = 'абвгдежзийклмнопрстуфхцчшщъьюя'
def is_pangram(sentence):
return not len([1 for char in __cyrillic if char not in sentence.lower()])
def char_histogram(sentence):
hystogram = {}
for symbol in sentence:
hystogram[symbol] = hystogram.setdefault(symbol, 0) + 1
return hystogram
def sort_by(compare, args):
- for arg_number in range(0, len(args) - 1):
- for bubble in range(0, len(args) - 1 - arg_number):
- if compare(args[bubble], args[bubble + 1]) > 0:
- args[bubble], args[bubble + 1] = args[bubble + 1], args[bubble]
- return args
+ return sorted(args, key=functools.cmp_to_key(compare))
def group_by_type(dictionary):
type_dict = {}
for key in dictionary:
type_dict.setdefault(type(key), {})[key] = dictionary[key]
return type_dict
def anagrams(words):
groups = {}
for word in words:
groups.setdefault(frozenset(char_histogram(word).items()), []).append(word)
return [groups[group] for group in groups]

Данаил обнови решението на 15.03.2014 17:13 (преди над 10 години)

import functools
+
__cyrillic = 'абвгдежзийклмнопрстуфхцчшщъьюя'
def is_pangram(sentence):
return not len([1 for char in __cyrillic if char not in sentence.lower()])
def char_histogram(sentence):
hystogram = {}
for symbol in sentence:
hystogram[symbol] = hystogram.setdefault(symbol, 0) + 1
return hystogram
def sort_by(compare, args):
return sorted(args, key=functools.cmp_to_key(compare))
def group_by_type(dictionary):
type_dict = {}
for key in dictionary:
type_dict.setdefault(type(key), {})[key] = dictionary[key]
return type_dict
def anagrams(words):
groups = {}
for word in words:
groups.setdefault(frozenset(char_histogram(word).items()), []).append(word)
return [groups[group] for group in groups]

Данаил обнови решението на 16.03.2014 00:03 (преди над 10 години)

import functools
__cyrillic = 'абвгдежзийклмнопрстуфхцчшщъьюя'
def is_pangram(sentence):
return not len([1 for char in __cyrillic if char not in sentence.lower()])
def char_histogram(sentence):
hystogram = {}
for symbol in sentence:
hystogram[symbol] = hystogram.setdefault(symbol, 0) + 1
return hystogram
def sort_by(compare, args):
return sorted(args, key=functools.cmp_to_key(compare))
def group_by_type(dictionary):
type_dict = {}
for key in dictionary:
type_dict.setdefault(type(key), {})[key] = dictionary[key]
return type_dict
def anagrams(words):
groups = {}
for word in words:
- groups.setdefault(frozenset(char_histogram(word).items()), []).append(word)
+ groups.setdefault(frozenset(char_histogram(word.lower())), []).append(word)
return [groups[group] for group in groups]

Анаграма е дума или фраза образувана от буквите на друга дума или фраза, чрез пермутация.

  • Твоето решение не прави разлика между буква и символ
  • return not len(...) е лош начин да върнеш булева стойност дали дължината на дадена колекция е нула
  • Константите в Python се пишат в SCREAMING_SNAKE_CASE и не са private

Данаил обнови решението на 16.03.2014 16:13 (преди над 10 години)

import functools
-__cyrillic = 'абвгдежзийклмнопрстуфхцчшщъьюя'
+CYRILLIC = 'абвгдежзийклмнопрстуфхцчшщъьюя'
def is_pangram(sentence):
- return not len([1 for char in __cyrillic if char not in sentence.lower()])
+ return len([1 for char in __cyrillic if char not in sentence.lower()]) == 0
def char_histogram(sentence):
hystogram = {}
for symbol in sentence:
hystogram[symbol] = hystogram.setdefault(symbol, 0) + 1
return hystogram
def sort_by(compare, args):
return sorted(args, key=functools.cmp_to_key(compare))
def group_by_type(dictionary):
type_dict = {}
for key in dictionary:
type_dict.setdefault(type(key), {})[key] = dictionary[key]
return type_dict
def anagrams(words):
groups = {}
for word in words:
- groups.setdefault(frozenset(char_histogram(word.lower())), []).append(word)
+ letters = "".join(char for char in word.lower() if char.isalpha())
+ groups.setdefault(frozenset(char_histogram(letters)), []).append(word)
return [groups[group] for group in groups]

Данаил обнови решението на 16.03.2014 16:14 (преди над 10 години)

import functools
CYRILLIC = 'абвгдежзийклмнопрстуфхцчшщъьюя'
def is_pangram(sentence):
- return len([1 for char in __cyrillic if char not in sentence.lower()]) == 0
+ return len([1 for char in CYRILLIC if char not in sentence.lower()]) == 0
def char_histogram(sentence):
hystogram = {}
for symbol in sentence:
hystogram[symbol] = hystogram.setdefault(symbol, 0) + 1
return hystogram
def sort_by(compare, args):
return sorted(args, key=functools.cmp_to_key(compare))
def group_by_type(dictionary):
type_dict = {}
for key in dictionary:
type_dict.setdefault(type(key), {})[key] = dictionary[key]
return type_dict
def anagrams(words):
groups = {}
for word in words:
letters = "".join(char for char in word.lower() if char.isalpha())
groups.setdefault(frozenset(char_histogram(letters)), []).append(word)
return [groups[group] for group in groups]

Данаил обнови решението на 19.03.2014 00:02 (преди над 10 години)

import functools
CYRILLIC = 'абвгдежзийклмнопрстуфхцчшщъьюя'
+
def is_pangram(sentence):
return len([1 for char in CYRILLIC if char not in sentence.lower()]) == 0
+
def char_histogram(sentence):
hystogram = {}
for symbol in sentence:
hystogram[symbol] = hystogram.setdefault(symbol, 0) + 1
return hystogram
+
def sort_by(compare, args):
return sorted(args, key=functools.cmp_to_key(compare))
+
def group_by_type(dictionary):
type_dict = {}
for key in dictionary:
type_dict.setdefault(type(key), {})[key] = dictionary[key]
return type_dict
+
def anagrams(words):
groups = {}
for word in words:
letters = "".join(char for char in word.lower() if char.isalpha())
groups.setdefault(frozenset(char_histogram(letters)), []).append(word)
- return [groups[group] for group in groups]
+ return [groups[group] for group in groups]