Решение на Пет функции от Атанас Димитров

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

Към профила на Атанас Димитров

Резултати

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

Код

def is_pangram(sentence):
cyrillic_lower = ('абвгдежзийклмнопрстуфхцчшщъьюя')
cyrillic_upper = ('АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЬЮЯ')
for index in range(len(cyrillic_lower)):
if cyrillic_lower[index] not in sentence and \
cyrillic_upper[index] not in sentence:
return False
return True
def char_histogram(text):
result = {}
for letter in text:
if letter not in result:
result[letter] = text.count(letter)
return result
def sort_by(func, arguments):
result = arguments.copy()
for i in range(len(result) - 1):
index_min = i
for j in range (i + 1, len(result)):
if func(result[index_min], result[j]) > 0:
index_min = j
if index_min != i:
element_to_insert = result[index_min]
result.remove(element_to_insert)
result.insert(i, element_to_insert)
return result
def group_by_type(dictionary):
result = {}
while len(dictionary):
item = dictionary.popitem()
if type(item[0]) in result:
key_value = result[type(item[0])]
key_value.update([item])
result[type(item[0])] = key_value
else:
result[type(item[0])] = {item[0]: item[1]}
return result
def letter_histogram(word):
result = {}
low_word = word.lower()
for letter in low_word:
if letter.isalpha() and letter not in result:
result[letter] = low_word.count(letter)
return result
def anagrams(words):
flawed_result = []
for word in words:
partial_result = []
for other_word in words:
if letter_histogram(word) == letter_histogram(other_word):
partial_result.append(other_word)
flawed_result.insert(0,partial_result)
result = []
for item in flawed_result:
if item not in result:
result.insert(0,item)
return result

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

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

OK

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

Атанас обнови решението на 14.03.2014 22:59 (преди над 10 години)

+def is_pangram(sentence):
+ cyrillic_lower = ('абвгдежзийклмнопрстуфхцчшщъьюя')
+ cyrillic_upper = ('АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЬЮЯ')
+ for index in range(len(cyrillic_lower)):
+ if cyrillic_lower[index] not in sentence and \
+ cyrillic_upper[index] not in sentence:
+ return False
+ return True
+
+
+def char_histogram(text):
+ result = {}
+ for letter in text:
+ if letter not in result:
+ result[letter] = text.count(letter)
+ return result
+
+def sort_by(func, arguments):
+ for i in range(len(arguments) - 1):
+ for j in range (i + 1, len(arguments)):
+ if func(arguments[i], arguments[j]) > 0:
+ temporary = arguments[i]
+ arguments[i] = arguments[j]
+ arguments[j] = temporary
+ return arguments
+
+
+def group_by_type(dictionary):
+ result = {}
+ while len(dictionary):
+ item = dictionary.popitem()
+ if type(item[0]) in result:
+ key_value = result[type(item[0])]
+ key_value.update([item])
+ result[type(item[0])] = key_value
+ else:
+ result[type(item[0])] = {item[0]: item[1]}
+ return result
+
+
+def anagrams(words):
+ almost_result = [[other_word for other_word in words \
+ if char_histogram(other_word) == char_histogram(word)] \
+ for word in words]
+ result = []
+ for item in almost_result:
+ if item not in result:
+ result.insert(0, item)
+ return result

Анаграма е дума или фраза образувана от буквите на друга дума или фраза, чрез пермутация.

  • Твоето решение не прави разлика между буква и символ.
  • Опитай се да намериш случай, в който твоята имплементация на sort_by се чупи

Атанас обнови решението на 17.03.2014 22:35 (преди над 10 години)

def is_pangram(sentence):
cyrillic_lower = ('абвгдежзийклмнопрстуфхцчшщъьюя')
cyrillic_upper = ('АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЬЮЯ')
for index in range(len(cyrillic_lower)):
if cyrillic_lower[index] not in sentence and \
cyrillic_upper[index] not in sentence:
return False
return True
def char_histogram(text):
result = {}
for letter in text:
if letter not in result:
result[letter] = text.count(letter)
return result
def sort_by(func, arguments):
- for i in range(len(arguments) - 1):
- for j in range (i + 1, len(arguments)):
- if func(arguments[i], arguments[j]) > 0:
- temporary = arguments[i]
- arguments[i] = arguments[j]
- arguments[j] = temporary
- return arguments
+ result = arguments
+ for i in range(len(result) - 1):
+ index_min = i
+ for j in range (i + 1, len(result)):
+ if func(result[index_min], result[j]) > 0:
+ index_min = j
+ if index_min != i:
+ element_to_insert = result[index_min]
+ result.remove(element_to_insert)
+ result.insert(i, element_to_insert)
+ return result
def group_by_type(dictionary):
result = {}
while len(dictionary):
item = dictionary.popitem()
if type(item[0]) in result:
key_value = result[type(item[0])]
key_value.update([item])
result[type(item[0])] = key_value
else:
result[type(item[0])] = {item[0]: item[1]}
return result
+def letter_histogram(word):
+ result = {}
+ for letter in word.lower():
+ if letter.isalpha() and letter not in result:
+ result[letter] = word.count(letter)
+ return result
+
def anagrams(words):
- almost_result = [[other_word for other_word in words \
- if char_histogram(other_word) == char_histogram(word)] \
- for word in words]
+ flawed_result = []
+ for word in words:
+ partial_result = []
+ for another_word in words:
+ if letter_histogram(word) == letter_histogram(another_word):
+ partial_result.append(another_word)
+ flawed_result.insert(0,partial_result)
result = []
- for item in almost_result:
+ for item in flawed_result:
if item not in result:
- result.insert(0, item)
+ result.insert(0,item)
return result

Атанас обнови решението на 17.03.2014 23:15 (преди над 10 години)

def is_pangram(sentence):
cyrillic_lower = ('абвгдежзийклмнопрстуфхцчшщъьюя')
cyrillic_upper = ('АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЬЮЯ')
for index in range(len(cyrillic_lower)):
if cyrillic_lower[index] not in sentence and \
cyrillic_upper[index] not in sentence:
return False
return True
def char_histogram(text):
result = {}
for letter in text:
if letter not in result:
result[letter] = text.count(letter)
return result
+
def sort_by(func, arguments):
result = arguments
for i in range(len(result) - 1):
index_min = i
for j in range (i + 1, len(result)):
if func(result[index_min], result[j]) > 0:
index_min = j
if index_min != i:
element_to_insert = result[index_min]
result.remove(element_to_insert)
result.insert(i, element_to_insert)
return result
def group_by_type(dictionary):
result = {}
while len(dictionary):
item = dictionary.popitem()
if type(item[0]) in result:
key_value = result[type(item[0])]
key_value.update([item])
result[type(item[0])] = key_value
else:
result[type(item[0])] = {item[0]: item[1]}
return result
def letter_histogram(word):
result = {}
for letter in word.lower():
if letter.isalpha() and letter not in result:
result[letter] = word.count(letter)
return result
+
def anagrams(words):
flawed_result = []
for word in words:
partial_result = []
for another_word in words:
if letter_histogram(word) == letter_histogram(another_word):
partial_result.append(another_word)
flawed_result.insert(0,partial_result)
result = []
for item in flawed_result:
if item not in result:
result.insert(0,item)
- return result
+ return result

Атанас обнови решението на 18.03.2014 17:46 (преди над 10 години)

def is_pangram(sentence):
cyrillic_lower = ('абвгдежзийклмнопрстуфхцчшщъьюя')
cyrillic_upper = ('АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЬЮЯ')
for index in range(len(cyrillic_lower)):
if cyrillic_lower[index] not in sentence and \
cyrillic_upper[index] not in sentence:
return False
return True
def char_histogram(text):
result = {}
for letter in text:
if letter not in result:
result[letter] = text.count(letter)
return result
def sort_by(func, arguments):
result = arguments
for i in range(len(result) - 1):
index_min = i
for j in range (i + 1, len(result)):
if func(result[index_min], result[j]) > 0:
index_min = j
if index_min != i:
element_to_insert = result[index_min]
result.remove(element_to_insert)
result.insert(i, element_to_insert)
return result
def group_by_type(dictionary):
result = {}
while len(dictionary):
item = dictionary.popitem()
if type(item[0]) in result:
key_value = result[type(item[0])]
key_value.update([item])
result[type(item[0])] = key_value
else:
result[type(item[0])] = {item[0]: item[1]}
return result
def letter_histogram(word):
result = {}
- for letter in word.lower():
+ low_word = word.lower()
+ for letter in low_word:
if letter.isalpha() and letter not in result:
- result[letter] = word.count(letter)
+ result[letter] = low_word.count(letter)
return result
def anagrams(words):
flawed_result = []
for word in words:
partial_result = []
- for another_word in words:
- if letter_histogram(word) == letter_histogram(another_word):
- partial_result.append(another_word)
+ for other_word in words:
+ if letter_histogram(word) == letter_histogram(other_word):
+ partial_result.append(other_word)
flawed_result.insert(0,partial_result)
result = []
for item in flawed_result:
if item not in result:
result.insert(0,item)
return result

Атанас обнови решението на 18.03.2014 20:30 (преди над 10 години)

def is_pangram(sentence):
cyrillic_lower = ('абвгдежзийклмнопрстуфхцчшщъьюя')
cyrillic_upper = ('АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЬЮЯ')
for index in range(len(cyrillic_lower)):
if cyrillic_lower[index] not in sentence and \
cyrillic_upper[index] not in sentence:
return False
return True
def char_histogram(text):
result = {}
for letter in text:
if letter not in result:
result[letter] = text.count(letter)
return result
def sort_by(func, arguments):
- result = arguments
+ result = arguments.copy()
for i in range(len(result) - 1):
index_min = i
for j in range (i + 1, len(result)):
if func(result[index_min], result[j]) > 0:
index_min = j
if index_min != i:
element_to_insert = result[index_min]
result.remove(element_to_insert)
result.insert(i, element_to_insert)
return result
def group_by_type(dictionary):
result = {}
while len(dictionary):
item = dictionary.popitem()
if type(item[0]) in result:
key_value = result[type(item[0])]
key_value.update([item])
result[type(item[0])] = key_value
else:
result[type(item[0])] = {item[0]: item[1]}
return result
def letter_histogram(word):
result = {}
low_word = word.lower()
for letter in low_word:
if letter.isalpha() and letter not in result:
result[letter] = low_word.count(letter)
return result
def anagrams(words):
flawed_result = []
for word in words:
partial_result = []
for other_word in words:
if letter_histogram(word) == letter_histogram(other_word):
partial_result.append(other_word)
flawed_result.insert(0,partial_result)
result = []
for item in flawed_result:
if item not in result:
result.insert(0,item)
return result