Решение на Пет функции от Владимир Начев

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

Към профила на Владимир Начев

Резултати

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

Код

BG_ALPHABET = "абвгдежзийклмнопрстуфхцчшщьъюя"
EN_ALPHABET = "abcdefghijklmnopqrstuvwxyz"
ALPHABET = BG_ALPHABET + EN_ALPHABET
def is_pangram(sentence):
for symbol in BG_ALPHABET:
if symbol not in sentence.lower():
return False
return True
def char_histogram(text):
histogram = {}
for symbol in text:
if symbol in histogram:
histogram[symbol] += 1
else:
histogram[symbol] = 1
return histogram
def sort_by(func, arguments):
to_be_sorted = arguments.copy()
length = len(to_be_sorted)
for i in range(1, length):
j = i-1
to_insert = to_be_sorted[i]
while j >= 0 and func( to_be_sorted[j], to_insert) > 0:
to_be_sorted[j + 1] = to_be_sorted[j]
j -= 1
to_be_sorted[j+1] = to_insert
return to_be_sorted
def group_by_type(dictionary):
result = {}
for key in dictionary:
result.setdefault(type(key),{})[key] = dictionary[key]
return result
def is_anagram(first, second):
first = first.lower()
second = second.lower()
first = [letter for letter in first if letter in ALPHABET]
second = [letter for letter in second if letter in ALPHABET]
first.sort()
second.sort()
return first == second
def is_member(double_nested, element):
for i in double_nested:
if element in i:
return True
return False
def anagrams(words):
result = []
anagrams_of_one_word = []
for word in words:
anagrams_of_one_word.clear()
if not is_member(result, word):
for other in words:
if is_anagram(word, other):
anagrams_of_one_word.append(other)
if len(anagrams_of_one_word):
result.append(list(anagrams_of_one_word))
return result

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

................
----------------------------------------------------------------------
Ran 16 tests in 0.009s

OK

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

Владимир обнови решението на 17.03.2014 19:12 (преди над 10 години)

+BG_ALPHABET = "абвгдежзийклмнопрстуфхцчшщьъюя"
+EN_ALPHABET = "abcdefghijklmnopqrstuvwxyz"
+ALPHABET = BG_ALPHABET + EN_ALPHABET
+
+def is_pangram(sentence):
+ for symbol in BG_ALPHABET:
+ if symbol not in sentence.lower():
+ return False
+ return True
+
+
+def char_histogram(text):
+ histogram = {}
+ for symbol in text:
+ if symbol in histogram:
+ histogram[symbol] += 1
+ else:
+ histogram[symbol] = 1
+ return histogram
+
+
+def sort_by(func, arguments):
+ to_be_sorted = arguments.copy()
+ length = len(to_be_sorted)
+ for i in range(1, length):
+ j = i-1
+ val = to_be_sorted[i]
+ while j >= 0 and func( to_be_sorted[j], val) > 0:
+ to_be_sorted[j + 1] = to_be_sorted[j]
+ j -= 1
+ to_be_sorted[j+1] = val
+ return to_be_sorted
+
+
+def group_by_type(dictionary):
+ result = {}
+ for key in dictionary:
+ result.setdefault(type(key),{})[key] = dictionary[key]
+ return result
+
+
+def is_anagram(first, second):
+ first = first.lower()
+ second = second.lower()
+ first = [letter for letter in first if letter in ALPHABET]
+ second = [letter for letter in second if letter in ALPHABET]
+ first.sort()
+ second.sort()
+ return first == second
+
+def is_member(list_of_lists, elem):
+ for i in list_of_lists:
+ if elem in i:
+ return True
+ return False
+
+
+def anagrams(words):
+ result = []
+ tmp = []
+ for word in words:
+ tmp.clear()
+ if not is_member(result, word):
+ for other in words:
+ if is_anagram(word, other):
+ tmp.append(other)
+ if len(tmp):
+ result.append(list(tmp))
+ return result

Владимир обнови решението на 19.03.2014 09:38 (преди над 10 години)

+__author__ = 'Vladimir'
+
+
BG_ALPHABET = "абвгдежзийклмнопрстуфхцчшщьъюя"
EN_ALPHABET = "abcdefghijklmnopqrstuvwxyz"
ALPHABET = BG_ALPHABET + EN_ALPHABET
def is_pangram(sentence):
for symbol in BG_ALPHABET:
if symbol not in sentence.lower():
return False
return True
def char_histogram(text):
histogram = {}
for symbol in text:
if symbol in histogram:
histogram[symbol] += 1
else:
histogram[symbol] = 1
return histogram
def sort_by(func, arguments):
to_be_sorted = arguments.copy()
length = len(to_be_sorted)
for i in range(1, length):
j = i-1
- val = to_be_sorted[i]
- while j >= 0 and func( to_be_sorted[j], val) > 0:
+ to_insert = to_be_sorted[i]
+ while j >= 0 and func( to_be_sorted[j], to_insert) > 0:
to_be_sorted[j + 1] = to_be_sorted[j]
j -= 1
- to_be_sorted[j+1] = val
+ to_be_sorted[j+1] = to_insert
return to_be_sorted
def group_by_type(dictionary):
result = {}
for key in dictionary:
result.setdefault(type(key),{})[key] = dictionary[key]
return result
def is_anagram(first, second):
first = first.lower()
second = second.lower()
first = [letter for letter in first if letter in ALPHABET]
second = [letter for letter in second if letter in ALPHABET]
first.sort()
second.sort()
return first == second
-def is_member(list_of_lists, elem):
- for i in list_of_lists:
- if elem in i:
+def is_member(double_nested, element):
+ for i in double_nested:
+ if element in i:
return True
return False
def anagrams(words):
result = []
- tmp = []
+ anagrams_of_one_word = []
for word in words:
- tmp.clear()
+ anagrams_of_one_word.clear()
if not is_member(result, word):
for other in words:
if is_anagram(word, other):
- tmp.append(other)
- if len(tmp):
+ anagrams_of_one_word.append(other)
- result.append(list(tmp))
+ if len(anagrams_of_one_word):
- return result
+ result.append(list(anagrams_of_one_word))
+ return result

Владимир обнови решението на 19.03.2014 09:39 (преди над 10 години)

-__author__ = 'Vladimir'
-
-
BG_ALPHABET = "абвгдежзийклмнопрстуфхцчшщьъюя"
EN_ALPHABET = "abcdefghijklmnopqrstuvwxyz"
ALPHABET = BG_ALPHABET + EN_ALPHABET
def is_pangram(sentence):
for symbol in BG_ALPHABET:
if symbol not in sentence.lower():
return False
return True
def char_histogram(text):
histogram = {}
for symbol in text:
if symbol in histogram:
histogram[symbol] += 1
else:
histogram[symbol] = 1
return histogram
def sort_by(func, arguments):
to_be_sorted = arguments.copy()
length = len(to_be_sorted)
for i in range(1, length):
j = i-1
to_insert = to_be_sorted[i]
while j >= 0 and func( to_be_sorted[j], to_insert) > 0:
to_be_sorted[j + 1] = to_be_sorted[j]
j -= 1
to_be_sorted[j+1] = to_insert
return to_be_sorted
def group_by_type(dictionary):
result = {}
for key in dictionary:
result.setdefault(type(key),{})[key] = dictionary[key]
return result
def is_anagram(first, second):
first = first.lower()
second = second.lower()
first = [letter for letter in first if letter in ALPHABET]
second = [letter for letter in second if letter in ALPHABET]
first.sort()
second.sort()
return first == second
def is_member(double_nested, element):
for i in double_nested:
if element in i:
return True
return False
def anagrams(words):
result = []
anagrams_of_one_word = []
for word in words:
anagrams_of_one_word.clear()
if not is_member(result, word):
for other in words:
if is_anagram(word, other):
anagrams_of_one_word.append(other)
if len(anagrams_of_one_word):
result.append(list(anagrams_of_one_word))
return result