Решение на Пет функции от Валентин Петров

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

Към профила на Валентин Петров

Резултати

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

Код

import collections
from itertools import groupby
from functools import cmp_to_key
def is_pangram( sentence ):
return not( bool( 30 - len( set( filter( str.isalpha,sentence.lower())))))
def char_histogram(text):
return {char : text.count(char) for char in set(text)}
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(dictionary):
keyfunc = lambda x: str(type(x[0]))
sortedinput = sorted(dictionary.items(),key=keyfunc)
return {k: {l[0]: l[1] for l in list(v)} \
for k,v in groupby(sortedinput,key=lambda x: type(x[0]))}

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

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

----------------------------------------------------------------------
Ran 16 tests in 0.014s

FAILED (errors=4)

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

Валентин обнови решението на 17.03.2014 20:05 (преди над 10 години)

+def is_pangram( sentence ):
+ return not( bool( 30 - len( set( filter( str.isalpha,sentence.lower())))))
+
+def char_histogram(text):
+ return {char : text.count(char) for char in set(text)}
+
+def sort_by(func, arguments):
+ return sorted(arguments, key=cmp_to_key(func))
+
+def group_by_type(dictionary):
+ keyfunc = lambda x: str(type(x[0]))
+ sortedinput = sorted(dictionary.items(),key=keyfunc)
+ return {k: list(v) for k,v in groupby(sortedinput,key=keyfunc)}
+

Валентин обнови решението на 17.03.2014 20:07 (преди над 10 години)

+import collections
+from itertools import groupby
+from functools import cmp_to_key
+
+
def is_pangram( sentence ):
return not( bool( 30 - len( set( filter( str.isalpha,sentence.lower())))))
def char_histogram(text):
return {char : text.count(char) for char in set(text)}
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(dictionary):
keyfunc = lambda x: str(type(x[0]))
sortedinput = sorted(dictionary.items(),key=keyfunc)
return {k: list(v) for k,v in groupby(sortedinput,key=keyfunc)}

Валентин обнови решението на 17.03.2014 20:37 (преди над 10 години)

import collections
from itertools import groupby
from functools import cmp_to_key
def is_pangram( sentence ):
return not( bool( 30 - len( set( filter( str.isalpha,sentence.lower())))))
def char_histogram(text):
return {char : text.count(char) for char in set(text)}
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(dictionary):
keyfunc = lambda x: str(type(x[0]))
sortedinput = sorted(dictionary.items(),key=keyfunc)
- return {k: list(v) for k,v in groupby(sortedinput,key=keyfunc)}
+ return {k: {l[0]: l[1] for l in list(v)} \
+ for k,v in groupby(sortedinput,key=lambda x: type(x[0]))}