Решение на Пет функции от Любослав Павлов

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

Към профила на Любослав Павлов

Резултати

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

Код

def is_pangram(sentence):
bul_alphabet = ('абвгдежзийклмнопрстуфхцчшщьъюя')
flag = True
for i in bul_alphabet:
if i in sentence.lower():
pass
else:
flag = False
return flag
def char_histogram(text):
dictionary = dict((i,text.count(i)) for i in text)
return dictionary
def sort_by(func, arguments):
for i in range(len(arguments)-1):
if func(arguments[i], arguments[i+1])>0:
for j in range(len(arguments)-1):
arguments[j], arguments[j+1] = arguments[j+1], arguments[j]
else : pass
return arguments
def group_by_type (dictionary):
new_dictionary = {}
for i in dictionary:
for j in dictionary:
if type(i) == type (j) and type(i) not in new_dictionary:
new_dictionary[type(i)] = {j: dictionary[j]}
elif type(i) == type (j) and type(i) in new_dictionary:
new_dictionary[type(i)][j] = dictionary[j]
else: pass
return new_dictionary
def anagrams(words):
result_list = []
for i in words:
test_word_1 = i
for j in words:
test_word_2 = j
if sorted(test_word_1.lower()) == sorted(test_word_2.lower()) and j not in result_list:
result_list.append(j)
else: pass
return result_list

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

FFFF...........F
======================================================================
FAIL: 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-1yvz3vf/test.py", line 109, in test_list_of_latin_anagrams
    set(map(frozenset, solution.anagrams(words))))
AssertionError: Items in the first set but not the second:
frozenset({'bau'})
frozenset({'moonstarer', 'astronomer'})
frozenset({'mary', 'ramy', 'army'})
frozenset({'bad credit', 'debit card'})
Items in the second set but not the first:
frozenset({'u', 'b', 'a'})
frozenset({'t', 'r', 's', 'n', 'o', 'm', 'e', 'a'})
frozenset({'t', 'r', 'i', 'd', 'e', 'b', 'c', ' ', 'a'})
frozenset({'y', 'm', 'r', 'a'})

======================================================================
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-1yvz3vf/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({'Dave Barry', 'Ray Adverb'})
Items in the second set but not the first:
frozenset({'e', 'y', 'v', 'r', 'R', 'd', 'a', 'b', ' ', 'A'})
frozenset({'y', 'v', 'r', 'D', 'e', 'B', ' ', 'a'})

======================================================================
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-1yvz3vf/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({'M', 'v', 'R', 'T', 'r', 'o', 'l', 'm', 'i', 'd', 'e', ' ', 'a'})
frozenset({'T', 'u', 'r', 's', 'o', 'm', 'i', 'e', 'C', ' '})
frozenset({'t', 'u', 'r', 'S', 'o', 'm', 'I', "'", 'e', 'c', ' '})
frozenset({'V', 't', 'r', 'l', 'o', 'L', 'm', 'I', 'd', 'e', ' ', 'a'})

======================================================================
FAIL: 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-1yvz3vf/test.py", line 117, in test_with_list_of_cyrilic_anagrams
    set(map(frozenset, solution.anagrams(words))))
AssertionError: Items in the first set but not the second:
frozenset({'акварел', 'кавалер'})
Items in the second set but not the first:
frozenset({'к', 'л', 'е', 'в', 'а', 'р'})

======================================================================
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-1yvz3vf/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] != [4, 5, 0, 1, 2, 3]

First differing element 0:
0
4

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

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

FAILED (failures=5)

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

Любослав обнови решението на 19.03.2014 16:46 (преди над 10 години)

+def is_pangram(sentence):
+ bul_alphabet = ('абвгдежзийклмнопрстуфхцчшщьъюя')
+ flag = True
+ for i in bul_alphabet:
+ if i in sentence.lower():
+ pass
+ else:
+ flag = False
+ return flag
+
+
+def char_histogram(text):
+ dictionary = dict((i,text.count(i)) for i in text)
+ return dictionary
+
+
+
+def sort_by(func, arguments):
+ for i in range(len(arguments)-1):
+ if func(arguments[i], arguments[i+1])>0:
+ for j in range(len(arguments)-1):
+ arguments[j], arguments[j+1] = arguments[j+1], arguments[j]
+ else : pass
+ return arguments
+
+def group_by_type (dictionary):
+ new_dictionary = {}
+ for i in dictionary:
+ for j in dictionary:
+ if type(i) == type (j) and type(i) not in new_dictionary:
+ new_dictionary[type(i)] = {j: dictionary[j]}
+ elif type(i) == type (j) and type(i) in new_dictionary:
+ new_dictionary[type(i)][j] = dictionary[j]
+ else: pass
+ return new_dictionary
+
+
+def anagrams(words):
+ result_list = []
+ for i in words:
+ test_word_1 = i
+ for j in words:
+ test_word_2 = j
+ if sorted(test_word_1.lower()) == sorted(test_word_2.lower()) and j not in result_list:
+ result_list.append(j)
+ else: pass
+ return result_list
+