Решение на Пет функции от Тихомир Янев

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

Към профила на Тихомир Янев

Резултати

  • 9 точки от тестове
  • 0 бонус точки
  • 9 точки общо
  • 14 успешни тест(а)
  • 2 неуспешни тест(а)

Код

import re
import functools
import itertools
def is_pangram(string):
return set('абвгдежзийклмнопрстуфхцчшщъьюя') == set(
re.sub('[^\w]', '', string.lower()))
def char_histogram(string):
return dict([(char, string.count(char)) for char in string])
def sort_by(func, arguments):
return sorted(arguments, key=functools.cmp_to_key(func))
def group_by_type(dictionary):
dict_types = dict([(x, {}) for x in set(map(type, dictionary))])
for key, value in dictionary.items():
dict_types[type(key)].update({key: value})
return dict_types
def anagrams(words):
storage = [(a, sorted(re.sub('[^\w]', '', a))) for a in words]
anagram_list = []
for key, group in itertools.groupby(storage, lambda x: x[1]):
anagram_list.append([x[0] for x in group])
return anagram_list

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

.FF.............
======================================================================
FAIL: test_with_different_cases (test.TestAnagrams)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140319-21201-uuo7wj/test.py", line 125, in test_with_different_cases
    set(map(frozenset, solution.anagrams(words))))
AssertionError: Items in the first set but not the second:
frozenset({'Ray Adverb', 'Dave Barry'})
Items in the second set but not the first:
frozenset({'Dave Barry'})
frozenset({'Ray Adverb'})

======================================================================
FAIL: test_with_different_symbols (test.TestAnagrams)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140319-21201-uuo7wj/test.py", line 135, in test_with_different_symbols
    set(map(frozenset, solution.anagrams(words))))
AssertionError: Items in the first set but not the second:
frozenset({'Tom Cruise', "So I'm cuter"})
frozenset({'Tom Marvolo Riddle', 'I am Lord Voldemort'})
Items in the second set but not the first:
frozenset({'I am Lord Voldemort'})
frozenset({'Tom Marvolo Riddle'})
frozenset({"So I'm cuter"})
frozenset({'Tom Cruise'})

----------------------------------------------------------------------
Ran 16 tests in 0.012s

FAILED (failures=2)

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

Тихомир обнови решението на 13.03.2014 18:01 (преди над 10 години)

+import re, functools, itertools
+
+def is_pangram(string):
+ return set('абвгдежзийклмнопрстуфхцчшщъьюя') == set(re.sub('[^\w]', '', string.lower()))
+
+def char_histogram(string):
+ return dict([(char, string.count(char)) for char in string])
+
+def sort_by(func, arguments):
+ return sorted(arguments, key=functools.cmp_to_key(func))
+
+def group_by_type(dictionary):
+ dict_types = dict([(x, {}) for x in set(map(type, dictionary))])
+ for key, value in dictionary.items():
+ dict_types[type(key)].update({key: value})
+ return dict_types
+
+def anagrams(words):
+ storage, anagram_list = list(map(lambda a: (a, sorted(a)), sorted(words, key=len))), []
+ for key, group in itertools.groupby(storage, lambda x: x[1]):
+ anagram_list.append([x[0] for x in group])
+ return anagram_list

Тихомир обнови решението на 13.03.2014 18:06 (преди над 10 години)

import re, functools, itertools
def is_pangram(string):
- return set('абвгдежзийклмнопрстуфхцчшщъьюя') == set(re.sub('[^\w]', '', string.lower()))
+ alphabet = 'абвгдежзийклмнопрстуфхцчшщъьюя'
+ return set(alphabet) == set(re.sub('[^\w]', '', string.lower()))
def char_histogram(string):
return dict([(char, string.count(char)) for char in string])
def sort_by(func, arguments):
return sorted(arguments, key=functools.cmp_to_key(func))
def group_by_type(dictionary):
dict_types = dict([(x, {}) for x in set(map(type, dictionary))])
for key, value in dictionary.items():
dict_types[type(key)].update({key: value})
return dict_types
def anagrams(words):
- storage, anagram_list = list(map(lambda a: (a, sorted(a)), sorted(words, key=len))), []
+ storage = list(map(lambda a: (a, sorted(a)), sorted(words, key=len)))
+ anagram_list = []
for key, group in itertools.groupby(storage, lambda x: x[1]):
anagram_list.append([x[0] for x in group])
return anagram_list

Тихомир обнови решението на 17.03.2014 05:39 (преди над 10 години)

import re, functools, itertools
def is_pangram(string):
alphabet = 'абвгдежзийклмнопрстуфхцчшщъьюя'
return set(alphabet) == set(re.sub('[^\w]', '', string.lower()))
def char_histogram(string):
return dict([(char, string.count(char)) for char in string])
def sort_by(func, arguments):
return sorted(arguments, key=functools.cmp_to_key(func))
def group_by_type(dictionary):
dict_types = dict([(x, {}) for x in set(map(type, dictionary))])
for key, value in dictionary.items():
dict_types[type(key)].update({key: value})
return dict_types
def anagrams(words):
- storage = list(map(lambda a: (a, sorted(a)), sorted(words, key=len)))
+ storage = [(a, sorted(re.sub('[^\w]', '', a))) for a in words]
anagram_list = []
for key, group in itertools.groupby(storage, lambda x: x[1]):
anagram_list.append([x[0] for x in group])
return anagram_list

Тихомир обнови решението на 17.03.2014 05:51 (преди над 10 години)

-import re, functools, itertools
+import re
+import functools
+import itertools
def is_pangram(string):
alphabet = 'абвгдежзийклмнопрстуфхцчшщъьюя'
return set(alphabet) == set(re.sub('[^\w]', '', string.lower()))
def char_histogram(string):
return dict([(char, string.count(char)) for char in string])
def sort_by(func, arguments):
return sorted(arguments, key=functools.cmp_to_key(func))
def group_by_type(dictionary):
dict_types = dict([(x, {}) for x in set(map(type, dictionary))])
for key, value in dictionary.items():
dict_types[type(key)].update({key: value})
return dict_types
def anagrams(words):
storage = [(a, sorted(re.sub('[^\w]', '', a))) for a in words]
anagram_list = []
for key, group in itertools.groupby(storage, lambda x: x[1]):
anagram_list.append([x[0] for x in group])
return anagram_list

Тихомир обнови решението на 17.03.2014 07:36 (преди над 10 години)

import re
import functools
import itertools
def is_pangram(string):
- alphabet = 'абвгдежзийклмнопрстуфхцчшщъьюя'
- return set(alphabet) == set(re.sub('[^\w]', '', string.lower()))
+ return set('абвгдежзийклмнопрстуфхцчшщъьюя') == set(
+ re.sub('[^\w]', '', string.lower()))
def char_histogram(string):
return dict([(char, string.count(char)) for char in string])
def sort_by(func, arguments):
return sorted(arguments, key=functools.cmp_to_key(func))
def group_by_type(dictionary):
dict_types = dict([(x, {}) for x in set(map(type, dictionary))])
for key, value in dictionary.items():
dict_types[type(key)].update({key: value})
return dict_types
def anagrams(words):
storage = [(a, sorted(re.sub('[^\w]', '', a))) for a in words]
anagram_list = []
for key, group in itertools.groupby(storage, lambda x: x[1]):
anagram_list.append([x[0] for x in group])
return anagram_list