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

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

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

Резултати

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

Код

import functools
def is_pangram(sentance, alphabet='абвгдежзийклмнопрстуфхцчшщьъюя'):
return not False in map(lambda x: x in sentance.lower(), list(alphabet))
def char_histogram(text):
return dict(zip(sorted(text), [text.count(x) for x in sorted(text)]))
def sort_by(func, arg):
return sorted(arg, key=functools.cmp_to_key(func))
def filter_dict(items, key):
return dict(item for item in items if type(item[0]) == type(key))
def group_by_type(dictionary):
items = list(dictionary.items())
return {type(key): filter_dict(items, key) for (key, value) in items}
def anagrams(words):
result = set(tuple(filter(lambda x: is_pangram(x, word), words)) for word in words)
return list(map(list, result))

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

.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-1xhh0ti/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()

======================================================================
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-1xhh0ti/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({'I am Lord Voldemort', 'Tom Marvolo Riddle'})
frozenset({'Tom Cruise', "So I'm cuter"})
Items in the second set but not the first:
frozenset()

----------------------------------------------------------------------
Ran 16 tests in 0.015s

FAILED (failures=2)

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

Георги обнови решението на 17.03.2014 17:30 (преди над 10 години)

+def is_pangram(sentance, alphabet='абвгдежзийклмнопрстуфхцчшщьъюя'):
+ return not False in map(lambda x: x in sentance, list(alphabet))

Георги обнови решението на 17.03.2014 17:42 (преди над 10 години)

def is_pangram(sentance, alphabet='абвгдежзийклмнопрстуфхцчшщьъюя'):
return not False in map(lambda x: x in sentance, list(alphabet))
+
+def char_histogram(text):
+ return list(zip(set(text), [text.count(x) for x in set(text)]))

Георги обнови решението на 19.03.2014 15:26 (преди над 10 години)

+import functools
+
def is_pangram(sentance, alphabet='абвгдежзийклмнопрстуфхцчшщьъюя'):
- return not False in map(lambda x: x in sentance, list(alphabet))
+ return not False in map(lambda x: x in sentance.lower(), list(alphabet))
def char_histogram(text):
- return list(zip(set(text), [text.count(x) for x in set(text)]))
+ return dict(zip(sorted(text), [text.count(x) for x in sorted(text)]))
+
+def sort_by(func, arg):
+ return sorted(arg, key=functools.cmp_to_key(func))
+
+def anagrams(words):
+ result = set(tuple(filter(lambda x: is_pangram(x, word), words)) for word in words)
+ return list(map(list, result))

Георги обнови решението на 19.03.2014 15:43 (преди над 10 години)

import functools
def is_pangram(sentance, alphabet='абвгдежзийклмнопрстуфхцчшщьъюя'):
return not False in map(lambda x: x in sentance.lower(), list(alphabet))
def char_histogram(text):
return dict(zip(sorted(text), [text.count(x) for x in sorted(text)]))
def sort_by(func, arg):
return sorted(arg, key=functools.cmp_to_key(func))
+def filter_dict(items, key):
+ return dict(item for item in items if type(item[0]) == type(key))
+
+def group_by_type(dictionary):
+ items = list(dictionary.items())
+ return {type(key): filter_dict(items, key) for (key, value) in items}
+
def anagrams(words):
result = set(tuple(filter(lambda x: is_pangram(x, word), words)) for word in words)
return list(map(list, result))