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

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

Към профила на Милица Борисова

Резултати

  • 10 точки от тестове
  • 0 бонус точки
  • 10 точки общо
  • 16 успешни тест(а)
  • 0 неуспешни тест(а)

Код

def is_pangram(sentence):
sentence_letters = list(set(sentence.lower()))
cyrilic_alphabeth = "абвгдежзийклмнопрстуфхцчшщъьюя"
return len([x for x in sentence_letters if x.isalpha()
and x in cyrilic_alphabeth]) == 30
def char_histogram(sentence):
return {letter: list(sentence).count(letter) for letter in list(sentence)}
def sort_by(sorting_function, unsorted_list):
sorted_list = []
for item in unsorted_list:
sorted_list.append(item)
j = len(sorted_list) - 1
while sorting_function(sorted_list[j - 1],
sorted_list[j]) > 0 and j > 0:
sorted_list[j - 1], sorted_list[j] = \
sorted_list[j], sorted_list[j - 1]
j -= 1
return sorted_list
def group_by_type(dictionary):
types_dictionary = {}
for item in dictionary:
if type(item) in types_dictionary.keys():
types_dictionary[type(item)][item] = dictionary[item]
else:
types_dictionary[type(item)] = {}
types_dictionary[type(item)][item] = dictionary[item]
return types_dictionary
def is_anagrams(first_word, second_word):
first_word = [letter for letter in first_word if letter.isalpha()]
second_word = [letter for letter in second_word if letter.isalpha()]
first_word.sort()
second_word.sort()
return first_word == second_word
def anagrams(words):
list_anagrams = []
for word in words:
anagrams_of_current_word = [anagram for anagram in words
if is_anagrams(list(word.upper()),
list(anagram.upper()))]
if anagrams_of_current_word not in list_anagrams:
list_anagrams.append(anagrams_of_current_word)
return list_anagrams

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

................
----------------------------------------------------------------------
Ran 16 tests in 0.010s

OK

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

Милица обнови решението на 16.03.2014 00:02 (преди над 10 години)

+def is_pangram(sentence):
+ sentence_letters = list(set(sentence.lower()))
+ cyrilic_alphabeth = "абвгдежзийклмнопрстуфхцчшщъьюя"
+ return len([x for x in sentence_letters if x.isalpha()
+ and x in cyrilic_alphabeth]) == 30
+
+
+def char_histogram(sentence):
+ return {letter: list(sentence).count(letter) for letter in list(sentence)}
+
+
+def sort_by(sorting_function, sort_this):
+ for i in range(1, len(sort_this)):
+ j = i
+ while sorting_function(sort_this[j - 1], sort_this[j]) > 0 and j > 0:
+ sort_this[j - 1], sort_this[j] = sort_this[j], sort_this[j - 1]
+ j -= 1
+ return sort_this
+
+
+def group_by_type(dictionary):
+ new_dictionary = {}
+ for item in dictionary:
+ if type(item) in new_dictionary.keys():
+ new_dictionary[type(item)][item] = dictionary[item]
+ else:
+ new_dictionary[type(item)] = {}
+ new_dictionary[type(item)][item] = dictionary[item]
+ return new_dictionary
+
+
+def is_anagrams(first_word, second_word):
+ first_word = [letter for letter in first_word if letter.isalpha()]
+ second_word = [letter for letter in second_word if letter.isalpha()]
+ first_word.sort()
+ second_word.sort()
+ return first_word == second_word
+
+
+def anagrams(words):
+ list_anagrams = []
+ for word in words:
+ anagrams_of_current_word = [anagram for anagram in words
+ if is_anagrams(list(word.upper()),
+ list(anagram.upper()))]
+ if anagrams_of_current_word not in list_anagrams:
+ list_anagrams.append(anagrams_of_current_word)
+ return list_anagrams

Милица обнови решението на 17.03.2014 23:49 (преди над 10 години)

def is_pangram(sentence):
sentence_letters = list(set(sentence.lower()))
cyrilic_alphabeth = "абвгдежзийклмнопрстуфхцчшщъьюя"
return len([x for x in sentence_letters if x.isalpha()
and x in cyrilic_alphabeth]) == 30
def char_histogram(sentence):
return {letter: list(sentence).count(letter) for letter in list(sentence)}
-def sort_by(sorting_function, sort_this):
- for i in range(1, len(sort_this)):
+def sort_by(sorting_function, to_sort):
+ for i in range(1, len(to_sort)):
j = i
- while sorting_function(sort_this[j - 1], sort_this[j]) > 0 and j > 0:
- sort_this[j - 1], sort_this[j] = sort_this[j], sort_this[j - 1]
+ while sorting_function(to_sort[j - 1],
+ to_sort[j]) > 0 and j > 0:
+ to_sort[j - 1], to_sort[j] = to_sort[j], to_sort[j - 1]
j -= 1
- return sort_this
+ return to_sort
def group_by_type(dictionary):
- new_dictionary = {}
+ types_dictionary = {}
for item in dictionary:
- if type(item) in new_dictionary.keys():
- new_dictionary[type(item)][item] = dictionary[item]
+ if type(item) in types_dictionary.keys():
+ types_dictionary[type(item)][item] = dictionary[item]
else:
- new_dictionary[type(item)] = {}
- new_dictionary[type(item)][item] = dictionary[item]
- return new_dictionary
+ types_dictionary[type(item)] = {}
+ types_dictionary[type(item)][item] = dictionary[item]
+ return types_dictionary
def is_anagrams(first_word, second_word):
first_word = [letter for letter in first_word if letter.isalpha()]
second_word = [letter for letter in second_word if letter.isalpha()]
first_word.sort()
second_word.sort()
return first_word == second_word
def anagrams(words):
list_anagrams = []
for word in words:
anagrams_of_current_word = [anagram for anagram in words
if is_anagrams(list(word.upper()),
list(anagram.upper()))]
if anagrams_of_current_word not in list_anagrams:
list_anagrams.append(anagrams_of_current_word)
return list_anagrams

Милица обнови решението на 18.03.2014 19:23 (преди над 10 години)

def is_pangram(sentence):
sentence_letters = list(set(sentence.lower()))
cyrilic_alphabeth = "абвгдежзийклмнопрстуфхцчшщъьюя"
return len([x for x in sentence_letters if x.isalpha()
and x in cyrilic_alphabeth]) == 30
def char_histogram(sentence):
return {letter: list(sentence).count(letter) for letter in list(sentence)}
-def sort_by(sorting_function, to_sort):
+def sort_by(sorting_function, unsorted_list):
+ to_sort = unsorted_list
for i in range(1, len(to_sort)):
j = i
while sorting_function(to_sort[j - 1],
to_sort[j]) > 0 and j > 0:
to_sort[j - 1], to_sort[j] = to_sort[j], to_sort[j - 1]
j -= 1
return to_sort
def group_by_type(dictionary):
types_dictionary = {}
for item in dictionary:
if type(item) in types_dictionary.keys():
types_dictionary[type(item)][item] = dictionary[item]
else:
types_dictionary[type(item)] = {}
types_dictionary[type(item)][item] = dictionary[item]
return types_dictionary
def is_anagrams(first_word, second_word):
first_word = [letter for letter in first_word if letter.isalpha()]
second_word = [letter for letter in second_word if letter.isalpha()]
first_word.sort()
second_word.sort()
return first_word == second_word
def anagrams(words):
list_anagrams = []
for word in words:
anagrams_of_current_word = [anagram for anagram in words
if is_anagrams(list(word.upper()),
list(anagram.upper()))]
if anagrams_of_current_word not in list_anagrams:
list_anagrams.append(anagrams_of_current_word)
return list_anagrams
+

Милица обнови решението на 18.03.2014 22:14 (преди над 10 години)

def is_pangram(sentence):
sentence_letters = list(set(sentence.lower()))
cyrilic_alphabeth = "абвгдежзийклмнопрстуфхцчшщъьюя"
return len([x for x in sentence_letters if x.isalpha()
and x in cyrilic_alphabeth]) == 30
def char_histogram(sentence):
return {letter: list(sentence).count(letter) for letter in list(sentence)}
def sort_by(sorting_function, unsorted_list):
- to_sort = unsorted_list
- for i in range(1, len(to_sort)):
- j = i
- while sorting_function(to_sort[j - 1],
- to_sort[j]) > 0 and j > 0:
- to_sort[j - 1], to_sort[j] = to_sort[j], to_sort[j - 1]
+ sorted_list = []
+ for item in unsorted_list:
+ sorted_list.append(item)
+ j = len(sorted_list) - 1
+ while sorting_function(sorted_list[j - 1],
+ sorted_list[j]) > 0 and j > 0:
+ sorted_list[j - 1], sorted_list[j] = \
+ sorted_list[j], sorted_list[j - 1]
j -= 1
- return to_sort
+ return sorted_list
def group_by_type(dictionary):
types_dictionary = {}
for item in dictionary:
if type(item) in types_dictionary.keys():
types_dictionary[type(item)][item] = dictionary[item]
else:
types_dictionary[type(item)] = {}
types_dictionary[type(item)][item] = dictionary[item]
return types_dictionary
def is_anagrams(first_word, second_word):
first_word = [letter for letter in first_word if letter.isalpha()]
second_word = [letter for letter in second_word if letter.isalpha()]
first_word.sort()
second_word.sort()
return first_word == second_word
def anagrams(words):
list_anagrams = []
for word in words:
anagrams_of_current_word = [anagram for anagram in words
if is_anagrams(list(word.upper()),
list(anagram.upper()))]
if anagrams_of_current_word not in list_anagrams:
list_anagrams.append(anagrams_of_current_word)
return list_anagrams
-