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

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

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

Резултати

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

Код

from collections import defaultdict
from functools import cmp_to_key
def is_pangram(sentence):
alphabet = set('абвгдежзийклмнопрстуфхцчшщъьюя')
return alphabet.issubset(sentence.lower())
def char_histogram(text):
result = {}
for symbol in text:
result[symbol] = text.count(symbol)
return result
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(dictionary):
result = defaultdict(dict)
for key in dictionary.keys():
result[type(key)].update({key: dictionary[key]})
return dict(result)
def dictify(word):
result = {}
for letter in word.lower():
if letter.isalpha():
result[letter] = word.lower().count(letter)
return result
def generate_group(word, words):
return tuple([unit for unit in words
if dictify(unit) == dictify(word)])
def anagrams(words):
return [list(group) for group
in set([generate_group(word, words) for word in words])]

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

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

OK

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

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

+from collections import defaultdict
+from functools import cmp_to_key
+
+
+def is_pangram(sentence):
+ alphabet = set('абвгдежзийклмнопрстуфхцчшщъьюя')
+ return alphabet.issubset(sentence.lower())
+
+def char_histogram(text):
+ result = defaultdict()
+ for symbol in text:
+ result[symbol] = text.count(symbol)
+ return dict(result)
+
+def sort_by(func, arguments):
+ return sorted(arguments, key=cmp_to_key(func))
+
+def group_by_type(dictionary):
+ result = defaultdict(dict)
+ for key in dictionary.keys():
+ result[type(key)].update({key: dictionary[key]})
+ return dict(result)
+
+def dictify(word):
+ result = defaultdict()
+ for letter in word:
+ result[letter] = word.count(letter)
+ return dict(result)
+
+def generate_group(word, words):
+ return tuple([unit for unit in words
+ if dictify(unit) == dictify(word)])
+
+def anagrams(words):
+ return [list(group) for group
+ in set([generate_group(word, words) for word in words])]

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

from collections import defaultdict
+
from functools import cmp_to_key
def is_pangram(sentence):
alphabet = set('абвгдежзийклмнопрстуфхцчшщъьюя')
return alphabet.issubset(sentence.lower())
def char_histogram(text):
result = defaultdict()
for symbol in text:
result[symbol] = text.count(symbol)
return dict(result)
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(dictionary):
result = defaultdict(dict)
for key in dictionary.keys():
result[type(key)].update({key: dictionary[key]})
return dict(result)
def dictify(word):
result = defaultdict()
for letter in word:
result[letter] = word.count(letter)
return dict(result)
def generate_group(word, words):
return tuple([unit for unit in words
if dictify(unit) == dictify(word)])
def anagrams(words):
return [list(group) for group
in set([generate_group(word, words) for word in words])]

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

  • Твоето решение не прави разлика между буква и символ.
  • char_histogram и dictify правят едно и също нещо :)
  • В горните две не ти трябват defaultdict(), тъй като defaultdict без аргументи се държи като нормален dict

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

from collections import defaultdict
from functools import cmp_to_key
def is_pangram(sentence):
alphabet = set('абвгдежзийклмнопрстуфхцчшщъьюя')
return alphabet.issubset(sentence.lower())
def char_histogram(text):
result = defaultdict()
for symbol in text:
result[symbol] = text.count(symbol)
return dict(result)
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(dictionary):
result = defaultdict(dict)
for key in dictionary.keys():
result[type(key)].update({key: dictionary[key]})
return dict(result)
def dictify(word):
result = defaultdict()
- for letter in word:
- result[letter] = word.count(letter)
+ for letter in word.lower():
+ if letter.isalpha():
+ result[letter] = word.lower().count(letter)
return dict(result)
def generate_group(word, words):
return tuple([unit for unit in words
if dictify(unit) == dictify(word)])
def anagrams(words):
return [list(group) for group
in set([generate_group(word, words) for word in words])]

Иван обнови решението на 17.03.2014 00:06 (преди над 10 години)

from collections import defaultdict
from functools import cmp_to_key
def is_pangram(sentence):
alphabet = set('абвгдежзийклмнопрстуфхцчшщъьюя')
return alphabet.issubset(sentence.lower())
def char_histogram(text):
- result = defaultdict()
+ result = {}
for symbol in text:
result[symbol] = text.count(symbol)
- return dict(result)
+ return result
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(dictionary):
result = defaultdict(dict)
for key in dictionary.keys():
result[type(key)].update({key: dictionary[key]})
return dict(result)
def dictify(word):
- result = defaultdict()
+ result = {}
for letter in word.lower():
if letter.isalpha():
result[letter] = word.lower().count(letter)
- return dict(result)
+ return result
def generate_group(word, words):
return tuple([unit for unit in words
if dictify(unit) == dictify(word)])
def anagrams(words):
return [list(group) for group
in set([generate_group(word, words) for word in words])]

Иван обнови решението на 17.03.2014 16:56 (преди над 10 години)

from collections import defaultdict
from functools import cmp_to_key
def is_pangram(sentence):
alphabet = set('абвгдежзийклмнопрстуфхцчшщъьюя')
return alphabet.issubset(sentence.lower())
def char_histogram(text):
result = {}
for symbol in text:
result[symbol] = text.count(symbol)
return result
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(dictionary):
result = defaultdict(dict)
for key in dictionary.keys():
result[type(key)].update({key: dictionary[key]})
return dict(result)
def dictify(word):
result = {}
for letter in word.lower():
- if letter.isalpha():
+ if letter.isalnum():
result[letter] = word.lower().count(letter)
return result
def generate_group(word, words):
return tuple([unit for unit in words
if dictify(unit) == dictify(word)])
def anagrams(words):
return [list(group) for group
in set([generate_group(word, words) for word in words])]

Иван обнови решението на 17.03.2014 23:19 (преди над 10 години)

from collections import defaultdict
from functools import cmp_to_key
def is_pangram(sentence):
alphabet = set('абвгдежзийклмнопрстуфхцчшщъьюя')
return alphabet.issubset(sentence.lower())
+
def char_histogram(text):
result = {}
for symbol in text:
result[symbol] = text.count(symbol)
return result
+
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
+
def group_by_type(dictionary):
result = defaultdict(dict)
for key in dictionary.keys():
result[type(key)].update({key: dictionary[key]})
return dict(result)
+
def dictify(word):
result = {}
for letter in word.lower():
if letter.isalnum():
result[letter] = word.lower().count(letter)
return result
+
def generate_group(word, words):
return tuple([unit for unit in words
if dictify(unit) == dictify(word)])
+
def anagrams(words):
return [list(group) for group
- in set([generate_group(word, words) for word in words])]
+ in set([generate_group(word, words) for word in words])]

Иван обнови решението на 18.03.2014 13:15 (преди над 10 години)

from collections import defaultdict
from functools import cmp_to_key
def is_pangram(sentence):
alphabet = set('абвгдежзийклмнопрстуфхцчшщъьюя')
return alphabet.issubset(sentence.lower())
def char_histogram(text):
result = {}
for symbol in text:
result[symbol] = text.count(symbol)
return result
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(dictionary):
result = defaultdict(dict)
for key in dictionary.keys():
result[type(key)].update({key: dictionary[key]})
return dict(result)
def dictify(word):
result = {}
for letter in word.lower():
- if letter.isalnum():
+ if letter.isalpha():
result[letter] = word.lower().count(letter)
return result
def generate_group(word, words):
return tuple([unit for unit in words
if dictify(unit) == dictify(word)])
def anagrams(words):
return [list(group) for group
in set([generate_group(word, words) for word in words])]