Решение на Пет функции от Моника Илиева

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

Към профила на Моника Илиева

Резултати

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

Код

BULGARIAN_ALPHABET = [chr(letter) for letter in range(ord('а'), ord('я') + 1)
if chr(letter) != 'э' and chr(letter) != 'ы']
def is_pangram(string):
unique_letters_in_string = set([letter for letter in string.lower()
if letter in BULGARIAN_ALPHABET])
return len(unique_letters_in_string) == len(BULGARIAN_ALPHABET)
def char_histogram(string):
number_of_symbols = {}
for symbol in string:
number_of_symbols[symbol] = string.count(symbol)
return number_of_symbols
def sort_by(func, arguments):
sorted_elements = [element for element in arguments]
for position in range(0, len(sorted_elements)):
if func(arguments[position], arguments[position-1]) > 0 and not \
str(arguments[position]).isalpha():
return sorted(sorted_elements)
elif func(arguments[position], arguments[position-1]) > 0:
return sorted(sorted_elements, key=len)
return sorted_elements

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

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

======================================================================
ERROR: 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-1wyp548/test.py", line 74, in test_another_group_by_type
    solution.group_by_type({(1, 2): 12, ('a', 1): 1, 1: 'b', 'c': 15}))
AttributeError: 'module' object has no attribute 'group_by_type'

======================================================================
ERROR: 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-1wyp548/test.py", line 68, in test_group_by_type
    solution.group_by_type({'a': 12, 'b': 1, 1: 'foo'}))
AttributeError: 'module' object has no attribute 'group_by_type'

======================================================================
ERROR: test_group_by_type_empty (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-1wyp548/test.py", line 63, in test_group_by_type_empty
    self.assertEqual({}, solution.group_by_type({}))
AttributeError: 'module' object has no attribute 'group_by_type'

======================================================================
ERROR: 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-1wyp548/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}))
AttributeError: 'module' object has no attribute 'group_by_type'

======================================================================
ERROR: 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-1wyp548/test.py", line 90, in test_group_by_type_with_functions
    solution.group_by_type({
AttributeError: 'module' object has no attribute 'group_by_type'

======================================================================
FAIL: test_sort_by_empty (test.TestSortBy)
----------------------------------------------------------------------
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-1wyp548/test.py", line 44, in test_sort_by_empty
    self.assertEqual([], solution.sort_by(lambda x, y: x - y, []))
AssertionError: [] != None

======================================================================
FAIL: test_sort_by_simple_test (test.TestSortBy)
----------------------------------------------------------------------
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-1wyp548/test.py", line 54, in test_sort_by_simple_test
    solution.sort_by(lambda x, y: x % 2 - y % 2, [0, 1, 2, 3, 4, 5]))
AssertionError: Lists differ: [0, 2, 4, 1, 3, 5] != [0, 1, 2, 3, 4, 5]

First differing element 1:
2
1

- [0, 2, 4, 1, 3, 5]
+ [0, 1, 2, 3, 4, 5]

----------------------------------------------------------------------
Ran 16 tests in 0.016s

FAILED (failures=2, errors=9)

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

Моника обнови решението на 17.03.2014 20:40 (преди над 10 години)

+import itertools
+
+
+BULGARIAN_ALPHABET = [chr(letter) for letter in range(ord('а'), ord('я') + 1)
+ if chr(letter) != 'э' and chr(letter) != 'ы']
+
+
+def is_pangram(string):
+ uniq_letters = [letter.lower() for letter in string.lower()
+ if letter in BULGARIAN_ALPHABET]
+ return len(set(uniq_letters)) == len(BULGARIAN_ALPHABET)
+
+
+def char_histogram(string):
+ count_letters = {}
+ for letter in string:
+ count_letters[letter] = string.count(letter)
+ return count_letters
+
+
+def anagrams(words):
+ return [list(value) for key, value in
+ itertools.groupby(sorted(words, key=sorted), sorted)]

Моника обнови решението на 19.03.2014 09:19 (преди над 10 години)

-import itertools
-
-
BULGARIAN_ALPHABET = [chr(letter) for letter in range(ord('а'), ord('я') + 1)
if chr(letter) != 'э' and chr(letter) != 'ы']
def is_pangram(string):
uniq_letters = [letter.lower() for letter in string.lower()
if letter in BULGARIAN_ALPHABET]
return len(set(uniq_letters)) == len(BULGARIAN_ALPHABET)
def char_histogram(string):
count_letters = {}
for letter in string:
count_letters[letter] = string.count(letter)
return count_letters
-
-
-def anagrams(words):
- return [list(value) for key, value in
- itertools.groupby(sorted(words, key=sorted), sorted)]

Моника обнови решението на 19.03.2014 12:37 (преди над 10 години)

BULGARIAN_ALPHABET = [chr(letter) for letter in range(ord('а'), ord('я') + 1)
if chr(letter) != 'э' and chr(letter) != 'ы']
def is_pangram(string):
- uniq_letters = [letter.lower() for letter in string.lower()
- if letter in BULGARIAN_ALPHABET]
- return len(set(uniq_letters)) == len(BULGARIAN_ALPHABET)
+ unique_letters_in_string = set([letter for letter in string.lower()
+ if letter in BULGARIAN_ALPHABET])
+ return len(unique_letters_in_string) == len(BULGARIAN_ALPHABET)
def char_histogram(string):
- count_letters = {}
- for letter in string:
+ number_of_symbols = {}
- count_letters[letter] = string.count(letter)
+ for symbol in string:
- return count_letters
+ number_of_symbols[symbol] = string.count(symbol)
+ return number_of_symbols

Моника обнови решението на 19.03.2014 15:13 (преди над 10 години)

BULGARIAN_ALPHABET = [chr(letter) for letter in range(ord('а'), ord('я') + 1)
if chr(letter) != 'э' and chr(letter) != 'ы']
def is_pangram(string):
unique_letters_in_string = set([letter for letter in string.lower()
if letter in BULGARIAN_ALPHABET])
return len(unique_letters_in_string) == len(BULGARIAN_ALPHABET)
def char_histogram(string):
number_of_symbols = {}
for symbol in string:
number_of_symbols[symbol] = string.count(symbol)
return number_of_symbols
+
+
+def sort_by(func, arguments):
+ sorted_elements = [element for element in arguments]
+ for position in range(0, len(sorted_elements)):
+ if func(arguments[position], arguments[position-1]) > 0 and not \
+ str(arguments[position]).isalpha():
+ return sorted(sorted_elements)
+ elif func(arguments[position], arguments[position-1]) > 0:
+ return sorted(sorted_elements, key=len)
+ return sorted_elements

Моника обнови решението на 19.03.2014 15:23 (преди над 10 години)

BULGARIAN_ALPHABET = [chr(letter) for letter in range(ord('а'), ord('я') + 1)
if chr(letter) != 'э' and chr(letter) != 'ы']
def is_pangram(string):
unique_letters_in_string = set([letter for letter in string.lower()
if letter in BULGARIAN_ALPHABET])
return len(unique_letters_in_string) == len(BULGARIAN_ALPHABET)
def char_histogram(string):
number_of_symbols = {}
for symbol in string:
number_of_symbols[symbol] = string.count(symbol)
return number_of_symbols
def sort_by(func, arguments):
sorted_elements = [element for element in arguments]
for position in range(0, len(sorted_elements)):
if func(arguments[position], arguments[position-1]) > 0 and not \
- str(arguments[position]).isalpha():
+ str(arguments[position]).isalpha():
return sorted(sorted_elements)
elif func(arguments[position], arguments[position-1]) > 0:
return sorted(sorted_elements, key=len)
- return sorted_elements
+ return sorted_elements