Решение на Пет функции от Найден Найдев

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

Към профила на Найден Найдев

Резултати

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

Код

import functools
def is_pangram(expr):
alpha = 'абвгдежзийклмнопрстуфхцчшщьъюя'
return set(alpha) == {c for c in expr.lower() if c.islower()}
def char_histogram(expr):
return {c: expr.count(c) for c in expr}
def group_by_type(args):
return {type(v): {k_nest: v_nest for k_nest, v_nest in args.items() \
if type(v_nest) == type(v)} \
for k, v in args.items()}
def anagram(words):
tuple_list = []
for word in words:
tup = tuple(word_tup for word_tup in words \
if set(word_tup) == set(word))
tuple_list.append(tup)
return [list(anagram_words) for anagram_words in set(tuple_list)]
def sort_by(func, list_for_sort):
return sorted(list_for_sort, key=functools.cmp_to_key(func))
def is_narcistic(number, base=10):
return int(number, base) == sum(int(c)**len(number) for c in number)

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

EEEE..FF.FF.....
======================================================================
ERROR: test_list_of_latin_anagrams (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-1roybd7/test.py", line 109, in test_list_of_latin_anagrams
    set(map(frozenset, solution.anagrams(words))))
AttributeError: 'module' object has no attribute 'anagrams'

======================================================================
ERROR: 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-1roybd7/test.py", line 125, in test_with_different_cases
    set(map(frozenset, solution.anagrams(words))))
AttributeError: 'module' object has no attribute 'anagrams'

======================================================================
ERROR: 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-1roybd7/test.py", line 135, in test_with_different_symbols
    set(map(frozenset, solution.anagrams(words))))
AttributeError: 'module' object has no attribute 'anagrams'

======================================================================
ERROR: test_with_list_of_cyrilic_anagrams (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-1roybd7/test.py", line 117, in test_with_list_of_cyrilic_anagrams
    set(map(frozenset, solution.anagrams(words))))
AttributeError: 'module' object has no attribute 'anagrams'

======================================================================
FAIL: test_another_group_by_type (test.TestGroupByType)
----------------------------------------------------------------------
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-1roybd7/test.py", line 74, in test_another_group_by_type
    solution.group_by_type({(1, 2): 12, ('a', 1): 1, 1: 'b', 'c': 15}))
AssertionError: {<class 'tuple'>: {(1, 2): 12, ('a', 1): 1}, <class 'int'>: {1: 'b'}, <class 'st [truncated]... != {<class 'int'>: {(1, 2): 12, 'c': 15, ('a', 1): 1}, <class 'str'>: {1: 'b'}}
+ {<class 'str'>: {1: 'b'}, <class 'int'>: {'c': 15, (1, 2): 12, ('a', 1): 1}}
- {<class 'tuple'>: {(1, 2): 12, ('a', 1): 1},
-  <class 'str'>: {'c': 15},
-  <class 'int'>: {1: 'b'}}

======================================================================
FAIL: test_group_by_type (test.TestGroupByType)
----------------------------------------------------------------------
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-1roybd7/test.py", line 68, in test_group_by_type
    solution.group_by_type({'a': 12, 'b': 1, 1: 'foo'}))
AssertionError: {<class 'int'>: {1: 'foo'}, <class 'str'>: {'b': 1, 'a': 12}} != {<class 'int'>: {'b': 1, 'a': 12}, <class 'str'>: {1: 'foo'}}
- {<class 'str'>: {'a': 12, 'b': 1}, <class 'int'>: {1: 'foo'}}
+ {<class 'str'>: {1: 'foo'}, <class 'int'>: {'a': 12, 'b': 1}}

======================================================================
FAIL: test_group_by_type_with_frozen_set_key (test.TestGroupByType)
----------------------------------------------------------------------
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-1roybd7/test.py", line 80, in test_group_by_type_with_frozen_set_key
    solution.group_by_type({(1, 2): 12, ('a', 1): 1, test_set: 15}))
AssertionError: {<class 'frozenset'>: {frozenset({1, 2, 3}): 15}, <class 'tuple'>: {(1, 2): 12,  [truncated]... != {<class 'int'>: {(1, 2): 12, frozenset({1, 2, 3}): 15, ('a', 1): 1}}
+ {<class 'int'>: {frozenset({1, 2, 3}): 15, (1, 2): 12, ('a', 1): 1}}
- {<class 'frozenset'>: {frozenset({1, 2, 3}): 15},
-  <class 'tuple'>: {(1, 2): 12, ('a', 1): 1}}

======================================================================
FAIL: test_group_by_type_with_functions (test.TestGroupByType)
----------------------------------------------------------------------
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-1roybd7/test.py", line 93, in test_group_by_type_with_functions
    ('list', 'of', 'numbers'): [42, 73]
AssertionError: {<class 'function'>: {<function TestGroupByType.test_group_by_type_with_function [truncated]... != {<class 'list'>: {('list', 'of', 'numbers'): [42, 73]}, <class 'int'>: {'three': [truncated]...
Diff is 689 characters long. Set self.maxDiff to None to see it.

----------------------------------------------------------------------
Ran 16 tests in 0.031s

FAILED (failures=4, errors=4)

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

Найден обнови решението на 19.03.2014 13:51 (преди над 10 години)

+import functools
+
+def is_pangram(expr):
+ alpha = 'абвгдежзийклмнопрстуфхцчшщьъюя'
+ return set(alpha) == {c for c in expr.lower() if c.islower()}
+
+def char_histogram(expr):
+ return {c: expr.count(c) for c in expr}
+
+def group_by_type(args):
+ return {type(v): {k_nest: v_nest for k_nest, v_nest in args.items() \
+ if type(v_nest) == type(v)} \
+ for k, v in args.items()}
+
+def anagram(words):
+ tuple_list = []
+ for word in words:
+ tup = tuple(word_tup for word_tup in words \
+ if set(word_tup) == set(word))
+ tuple_list.append(tup)
+ return [list(anagram_words) for anagram_words in set(tuple_list)]
+
+def sort_by(func, list_for_sort):
+ return sorted(list_for_sort, key=functools.cmp_to_key(func))
+
+def is_narcistic(number, base=10):
+ return int(number, base) == sum(int(c)**len(number) for c in number)