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

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

Към профила на Цветислав Викторов

Резултати

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

Код

def is_pangram(sentance):
letters = []
for letter in sentance:
letter_low = letter.lower()
if letter not in letters and letter_low <= 'я' and letter_low >= 'а':
letters.append(letter.lower())
print(letters)
return len(letters) == 30
def char_histogram(text):
letters = []
symbols_count = {}
for letter in text:
if letter not in letters:
letters.append(letter)
for letter in letters:
counter = 0
for symbol in text:
if letter == symbol:
counter = counter + 1
symbols_count[letter] = counter
return symbols_count
def group_by_type(dictionary):
classes = []
final_dictionary = {}
for arg in dictionary:
if type(arg) not in classes:
classes.append(type(arg))
for arg_type in classes:
current = {}
for argument in dictionary:
if type(argument) == arg_type:
current[argument] = dictionary[argument]
final_dictionary[arg_type] = current
return final_dictionary
def anagrams(words):
anagram = []
for word in words:
letters = []
for letter in word:
if letter not in letters:
letters.append(letter)
words_list = []
for word_i in words:
letters_i = []
flag = True
for letter_i in word_i:
if letter_i not in letters_i:
letters_i.append(letter_i)
for i in letters:
if i not in letters_i:
flag = False
if flag == True:
words_list.append(word_i)
if words_list not in anagram:
anagram.append(words_list)
return anagram
def sort_by(func, arguments):
for word_1 in range(0,len(arguments)):
for word_2 in range(word_1,len(arguments)):
if func(arguments[word_1], arguments[word_2])>0:
a = arguments[word_1]
arguments[word_1] = arguments[word_2]
arguments[word_2] = a
return arguments

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

.FF............F
======================================================================
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-kxozaw/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({'Dave Barry'})
frozenset({'Ray Adverb'})

======================================================================
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-kxozaw/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({'I am Lord Voldemort'})
frozenset({'Tom Marvolo Riddle'})
frozenset({'Tom Cruise'})
frozenset({"So I'm cuter"})

======================================================================
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-kxozaw/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, 2, 4, 3, 1, 5]

First differing element 3:
1
3

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

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


----------------------------------------------------------------------
Ran 16 tests in 0.012s

FAILED (failures=3)

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

Цветислав обнови решението на 14.03.2014 15:07 (преди над 10 години)

+def is_pangram(sentance):
+ letters = []
+ for letter in sentance:
+ if letter not in letters and letter.lower()<='я' and letter.lower()>='а':
+ letters.append(letter.lower())
+ print(letters)
+ return len(letters)==30
+
+def char_histogram(text):
+ letters = []
+ symbols_count = {}
+ for letter in text:
+ if letter not in letters:
+ letters.append(letter)
+ for letter in letters:
+ counter = 0
+ for symbol in text:
+ if letter==symbol:
+ counter = counter + 1
+ symbols_count[letter]=counter
+ return symbols_count
+
+def group_by_type(dictionary):
+ classes = []
+ final_dictionary = {}
+ for class_arg in dictionary:
+ if type(class_arg) not in classes:
+ classes.append(type(class_arg))
+ for class_arg in classes:
+ current = {}
+ for argument in dictionary:
+ if type(argument)==class_arg:
+ current[argument]=dictionary[argument]
+ final_dictionary[class_arg]=current
+ return final_dictionary

Цветислав обнови решението на 16.03.2014 13:51 (преди над 10 години)

def is_pangram(sentance):
letters = []
for letter in sentance:
- if letter not in letters and letter.lower()<='я' and letter.lower()>='а':
+ letter_low = letter.lower()
+ if letter not in letters and letter_low <= 'я' and letter_low >= 'а':
letters.append(letter.lower())
print(letters)
- return len(letters)==30
+ return len(letters) == 30
def char_histogram(text):
letters = []
symbols_count = {}
for letter in text:
if letter not in letters:
letters.append(letter)
for letter in letters:
counter = 0
for symbol in text:
- if letter==symbol:
+ if letter == symbol:
counter = counter + 1
- symbols_count[letter]=counter
+ symbols_count[letter] = counter
return symbols_count
def group_by_type(dictionary):
classes = []
final_dictionary = {}
- for class_arg in dictionary:
- if type(class_arg) not in classes:
- classes.append(type(class_arg))
- for class_arg in classes:
+ for arg in dictionary:
+ if type(arg) not in classes:
+ classes.append(type(arg))
+ for arg_type in classes:
current = {}
for argument in dictionary:
- if type(argument)==class_arg:
- current[argument]=dictionary[argument]
+ if type(argument) == arg_type:
- final_dictionary[class_arg]=current
+ current[argument] = dictionary[argument]
- return final_dictionary
+ final_dictionary[arg_type] = current
+ return final_dictionary
+
+def anagrams(words):
+ anagram = []
+ for word in words:
+ letters = []
+ for letter in word:
+ if letter not in letters:
+ letters.append(letter)
+ words_list = []
+
+ for word_i in words:
+ letters_i = []
+ flag = True
+ for letter_i in word_i:
+ if letter_i not in letters_i:
+ letters_i.append(letter_i)
+
+ for i in letters:
+ if i not in letters_i:
+ flag = False
+ if flag == True:
+ words_list.append(word_i)
+ if words_list not in anagram:
+ anagram.append(words_list)
+ return anagram
+
+def sort_by(func, arguments):
+ for word_1 in range(0,len(arguments)):
+ for word_2 in range(word_1,len(arguments)):
+ if func(arguments[word_1], arguments[word_2])>0:
+ a = arguments[word_1]
+ arguments[word_1] = arguments[word_2]
+ arguments[word_2] = a
+ return arguments
+