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

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

Към профила на Иван Латунов

Резултати

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

Код

from functools import cmp_to_key
def is_pangram(sentance):
alphabet = set('абвгдежзийклмнопрстуфхцчшщъьюя')
checked = [False] * 30
lowered_str = set(sentance.lower()) - {'!', ' ', '.', '?', ','}
for i in lowered_str:
alphabet -= set(i)
return alphabet == set()
def char_histogram(string):
string_list = list(string)
count_list = []
for i in string_list:
count_list.append(string_list.count(i))
return dict(zip(string_list, count_list))
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(dictionary):
return_dict = {}
for i in dictionary:
return_dict[type(i)] = {}
for i in dictionary:
return_dict[type(i)][i] = dictionary.get(i)
return return_dict
def anagrams(words):
return words

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

FFFF............
======================================================================
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-1iyyo3j/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({'bad credit', 'debit card'})
frozenset({'mary', 'ramy', 'army'})
frozenset({'moonstarer', 'astronomer'})
frozenset({'bau'})
Items in the second set but not the first:
frozenset({'a', 'e', 'o', 'n', 'm', 's', 'r', 't'})
frozenset({'r', 'a', 'y', 'm'})
frozenset({'b', 'a', 'u'})
frozenset({'c', 'b', 'a', ' ', 'e', 'd', 'i', 'r', 't'})

======================================================================
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-1iyyo3j/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({'b', 'a', ' ', 'r', 'e', 'd', 'A', 'R', 'v', 'y'})
frozenset({'B', 'a', ' ', 'e', 'D', 'r', 'v', 'y'})

======================================================================
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-1iyyo3j/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({'Tom Marvolo Riddle', 'I am Lord Voldemort'})
frozenset({"So I'm cuter", 'Tom Cruise'})
Items in the second set but not the first:
frozenset({'a', ' ', 'e', 'd', 'I', 'o', 'm', 'L', 'r', 'V', 't', 'l'})
frozenset({'C', ' ', 'e', 'i', 'o', 'm', 's', 'r', 'u', 'T'})
frozenset({'c', ' ', "'", 'e', 'I', 'o', 'm', 'S', 'r', 'u', 't'})
frozenset({'a', ' ', 'e', 'R', 'i', 'd', 'o', 'M', 'l', 'r', 'm', 'T', 'v'})

======================================================================
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-1iyyo3j/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({'р', 'в', 'а', 'е', 'л', 'к'})

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

FAILED (failures=4)

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

Иван обнови решението на 19.03.2014 14:57 (преди над 10 години)

+def is_pangram(sentance):
+
+ alphabet = set('абвгдежзийклмнопрстуфхцчшщъьюя')
+ checked = [False] * 30
+ lowered_str = set(sentance.lower()) - {'!', ' ', '.', '?', ','}
+
+ for i in lowered_str:
+ alphabet -= set(i)
+
+ return alphabet == set()

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

def is_pangram(sentance):
alphabet = set('абвгдежзийклмнопрстуфхцчшщъьюя')
checked = [False] * 30
lowered_str = set(sentance.lower()) - {'!', ' ', '.', '?', ','}
for i in lowered_str:
alphabet -= set(i)
return alphabet == set()
+
+
+def char_histogram(string):
+
+ string_list = list(string)
+ count_list = []
+
+ for i in string_list:
+ count_list.append(string_list.count(i))
+
+ return dict(zip(string_list, count_list))
  • checked = [False] * 30 ?!
  • няма нужда да махаш препинателните знаци изрично
  • защо обхождаш множество по елементите му вадейки ги от друго множество вместо да образуваш директно разликата на двете ?

  • help(''.count)

  • няма смисъл в char_histogram да ползваш междинни контейнери. Строй си директно изхода. (Comprehension-ите са супер подходящи за подобни прости конструкции ;)

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

+from functools import cmp_to_key
+
+
def is_pangram(sentance):
alphabet = set('абвгдежзийклмнопрстуфхцчшщъьюя')
checked = [False] * 30
lowered_str = set(sentance.lower()) - {'!', ' ', '.', '?', ','}
for i in lowered_str:
alphabet -= set(i)
return alphabet == set()
def char_histogram(string):
string_list = list(string)
count_list = []
for i in string_list:
count_list.append(string_list.count(i))
return dict(zip(string_list, count_list))
+
+def sort_by(func, arguments):
+ return sorted(arguments, key=cmp_to_key(func))

Иван обнови решението на 19.03.2014 16:42 (преди над 10 години)

from functools import cmp_to_key
def is_pangram(sentance):
alphabet = set('абвгдежзийклмнопрстуфхцчшщъьюя')
checked = [False] * 30
lowered_str = set(sentance.lower()) - {'!', ' ', '.', '?', ','}
for i in lowered_str:
alphabet -= set(i)
return alphabet == set()
def char_histogram(string):
string_list = list(string)
count_list = []
for i in string_list:
count_list.append(string_list.count(i))
return dict(zip(string_list, count_list))
+
def sort_by(func, arguments):
- return sorted(arguments, key=cmp_to_key(func))
+ return sorted(arguments, key=cmp_to_key(func))
+
+
+def group_by_type(dictionary):
+
+ return_dict = {}
+
+ for i in dictionary:
+ return_dict[type(i)] = {}
+
+ for i in dictionary:
+ return_dict[type(i)][i] = dictionary.get(i)
+
+ return return_dict

Иван обнови решението на 19.03.2014 16:48 (преди над 10 години)

from functools import cmp_to_key
def is_pangram(sentance):
alphabet = set('абвгдежзийклмнопрстуфхцчшщъьюя')
checked = [False] * 30
lowered_str = set(sentance.lower()) - {'!', ' ', '.', '?', ','}
for i in lowered_str:
alphabet -= set(i)
return alphabet == set()
def char_histogram(string):
string_list = list(string)
count_list = []
for i in string_list:
count_list.append(string_list.count(i))
- return dict(zip(string_list, count_list))
+ return dict(zip(string_list, count_list))
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(dictionary):
-
+
return_dict = {}
for i in dictionary:
return_dict[type(i)] = {}
for i in dictionary:
return_dict[type(i)][i] = dictionary.get(i)
return return_dict
+
+
+def anagrams(words):
+ return words