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

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

Към профила на Пламен Димитров

Резултати

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

Код

ALPHABET = set(range(1072, 1104)) - {1099, 1101}
'''
1099 and 1101 aren't in cirilic alphabet
'''
def is_pangram(expresion):
if len(expresion) < 30:
return False
lower_case_expresion = expresion.lower()
for char in ALPHABET:
if chr(char) not in lower_case_expresion:
return False
return True
def char_histogram(expresion):
count_symbol = {}
for key in expresion:
if key in count_symbol:
count_symbol[key] += 1
else:
count_symbol[key] = 1
return count_symbol
def sort_by(function, arguments):
stopper = True
while stopper:
stopper = False
for index in range(0, len(arguments)-1):
if function(arguments[index], arguments[index+1]) > 0:
arguments[index], arguments[index+1] = \
arguments[index+1], arguments[index]
stopper = True
return arguments
def group_by_type(dictionary):
buffer_types = set()
for iterator in dictionary:
buffer_types.add(type(iterator))
current_values = {}
target = {}
for type_ in buffer_types:
for word in dictionary:
if type_ == type(word):
current_values[word] = dictionary[word]
target[type_] = dict(current_values)
current_values.clear()
return target
def make_a_host(expresion):
result_host = set()
lower_case_expresion = expresion.lower()
for char in lower_case_expresion:
if char.isalpha():
result_host.add(char)
return result_host
def anagrams(words):
iterated_word_host = set()
anagram = []
for index in range(len(words)):
current_result = []
if index not in iterated_word_host:
current_word_host = make_a_host(words[index])
iterated_word_host.add(index)
current_result.append(words[index])
else:
continue
for i in range(index+1, len(words)):
if i in iterated_word_host:
continue
current_host = make_a_host(words[i])
if current_host == current_word_host:
current_result.append(words[i])
iterated_word_host.add(i)
anagram.append(current_result)
return anagram

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

................
----------------------------------------------------------------------
Ran 16 tests in 0.043s

OK

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

Пламен обнови решението на 17.03.2014 18:42 (преди около 10 години)

+ALPHABET = set(range(1072, 1104)) - {1099, 1101}
+'''
+1099 and 1101 are't in cirilic alphabet
+'''
+
+
+def is_pangram(expresion):
+ if len(expresion) < 30:
+ return False
+ lower_case_expresion = expresion.lower()
+ for a_char in ALPHABET:
+ if chr(a_char) not in lower_case_expresion:
+ return False
+ return True
+
+
+def char_histogram(expresion):
+ count_symbol = {}
+ for key in expresion:
+ if key in count_symbol:
+ count_symbol[key] += 1
+ else:
+ count_symbol[key] = 1
+ return count_symbol
+
+
+def sort_by(function, arguments):
+ stopper = True
+ while stopper:
+ stopper = False
+ for index in range(0, len(arguments)-1):
+ if function(arguments[index], arguments[index+1]) > 0:
+ arguments[index], arguments[index+1] = \
+ arguments[index+1], arguments[index]
+ stopper = True
+ return arguments
+
+
+def group_by_type(dictionary):
+ buffer_types = set()
+ for iterator in dictionary:
+ buffer_types.add(type(iterator))
+
+ current_values = {}
+ target = {}
+ for type_ in buffer_types:
+ for word in dictionary:
+ if type_ == type(word):
+ current_values[word] = dictionary[word]
+ target[type_] = dict(current_values)
+ current_values.clear()
+ return target
+
+
+def make_a_host(expresion):
+ result_host = set()
+ for char in expresion:
+ if char.isalpha():
+ result_host.add(char)
+ return result_host
+
+
+def anagrams(words):
+ iterated_word_host = set()
+ anagram = []
+ for index in range(len(words)):
+ temp_result = []
+ if index not in iterated_word_host:
+ current_word_host = make_a_host(words[index])
+ iterated_word_host.add(index)
+ temp_result.append(words[index])
+ else:
+ continue
+ for i in range(index+1, len(words)):
+ if i in iterated_word_host:
+ continue
+ temp_set = make_a_host(words[i])
+ if temp_set == current_word_host:
+ temp_result.append(words[i])
+ iterated_word_host.add(i)
+ anagram.append(temp_result)
+ return anagram

Пламен обнови решението на 17.03.2014 21:57 (преди около 10 години)

ALPHABET = set(range(1072, 1104)) - {1099, 1101}
'''
-1099 and 1101 are't in cirilic alphabet
+1099 and 1101 aren't in cirilic alphabet
'''
def is_pangram(expresion):
if len(expresion) < 30:
return False
lower_case_expresion = expresion.lower()
for a_char in ALPHABET:
if chr(a_char) not in lower_case_expresion:
return False
return True
def char_histogram(expresion):
count_symbol = {}
for key in expresion:
if key in count_symbol:
count_symbol[key] += 1
else:
count_symbol[key] = 1
return count_symbol
def sort_by(function, arguments):
stopper = True
while stopper:
stopper = False
for index in range(0, len(arguments)-1):
if function(arguments[index], arguments[index+1]) > 0:
arguments[index], arguments[index+1] = \
arguments[index+1], arguments[index]
stopper = True
return arguments
def group_by_type(dictionary):
buffer_types = set()
for iterator in dictionary:
buffer_types.add(type(iterator))
current_values = {}
target = {}
for type_ in buffer_types:
for word in dictionary:
if type_ == type(word):
current_values[word] = dictionary[word]
target[type_] = dict(current_values)
current_values.clear()
return target
def make_a_host(expresion):
result_host = set()
for char in expresion:
if char.isalpha():
result_host.add(char)
return result_host
def anagrams(words):
iterated_word_host = set()
anagram = []
for index in range(len(words)):
temp_result = []
if index not in iterated_word_host:
current_word_host = make_a_host(words[index])
iterated_word_host.add(index)
temp_result.append(words[index])
else:
continue
for i in range(index+1, len(words)):
if i in iterated_word_host:
continue
temp_set = make_a_host(words[i])
if temp_set == current_word_host:
temp_result.append(words[i])
iterated_word_host.add(i)
anagram.append(temp_result)
return anagram

Пламен обнови решението на 18.03.2014 21:53 (преди около 10 години)

ALPHABET = set(range(1072, 1104)) - {1099, 1101}
'''
-1099 and 1101 aren't in cirilic alphabet
+1099 and 1101 are't in cirilic alphabet
'''
def is_pangram(expresion):
if len(expresion) < 30:
return False
lower_case_expresion = expresion.lower()
- for a_char in ALPHABET:
- if chr(a_char) not in lower_case_expresion:
+ for char in ALPHABET:
+ if chr(char) not in lower_case_expresion:
return False
return True
def char_histogram(expresion):
count_symbol = {}
for key in expresion:
if key in count_symbol:
count_symbol[key] += 1
else:
count_symbol[key] = 1
return count_symbol
def sort_by(function, arguments):
stopper = True
while stopper:
stopper = False
for index in range(0, len(arguments)-1):
if function(arguments[index], arguments[index+1]) > 0:
arguments[index], arguments[index+1] = \
arguments[index+1], arguments[index]
stopper = True
return arguments
def group_by_type(dictionary):
buffer_types = set()
for iterator in dictionary:
buffer_types.add(type(iterator))
current_values = {}
target = {}
for type_ in buffer_types:
for word in dictionary:
if type_ == type(word):
current_values[word] = dictionary[word]
target[type_] = dict(current_values)
current_values.clear()
return target
def make_a_host(expresion):
result_host = set()
- for char in expresion:
+ lower_case_expresion = expresion.lower()
+ for char in lower_case_expresion:
if char.isalpha():
result_host.add(char)
return result_host
def anagrams(words):
iterated_word_host = set()
anagram = []
for index in range(len(words)):
- temp_result = []
+ current_result = []
if index not in iterated_word_host:
current_word_host = make_a_host(words[index])
iterated_word_host.add(index)
- temp_result.append(words[index])
+ current_result.append(words[index])
else:
continue
for i in range(index+1, len(words)):
if i in iterated_word_host:
continue
- temp_set = make_a_host(words[i])
- if temp_set == current_word_host:
- temp_result.append(words[i])
+ current_host = make_a_host(words[i])
+ if current_host == current_word_host:
+ current_result.append(words[i])
iterated_word_host.add(i)
- anagram.append(temp_result)
+ anagram.append(current_result)
return anagram

Пламен обнови решението на 18.03.2014 21:54 (преди около 10 години)

ALPHABET = set(range(1072, 1104)) - {1099, 1101}
'''
-1099 and 1101 are't in cirilic alphabet
+1099 and 1101 aren't in cirilic alphabet
'''
def is_pangram(expresion):
if len(expresion) < 30:
return False
lower_case_expresion = expresion.lower()
for char in ALPHABET:
if chr(char) not in lower_case_expresion:
return False
return True
def char_histogram(expresion):
count_symbol = {}
for key in expresion:
if key in count_symbol:
count_symbol[key] += 1
else:
count_symbol[key] = 1
return count_symbol
def sort_by(function, arguments):
stopper = True
while stopper:
stopper = False
for index in range(0, len(arguments)-1):
if function(arguments[index], arguments[index+1]) > 0:
arguments[index], arguments[index+1] = \
arguments[index+1], arguments[index]
stopper = True
return arguments
def group_by_type(dictionary):
buffer_types = set()
for iterator in dictionary:
buffer_types.add(type(iterator))
current_values = {}
target = {}
for type_ in buffer_types:
for word in dictionary:
if type_ == type(word):
current_values[word] = dictionary[word]
target[type_] = dict(current_values)
current_values.clear()
return target
def make_a_host(expresion):
result_host = set()
lower_case_expresion = expresion.lower()
for char in lower_case_expresion:
if char.isalpha():
result_host.add(char)
return result_host
def anagrams(words):
iterated_word_host = set()
anagram = []
for index in range(len(words)):
current_result = []
if index not in iterated_word_host:
current_word_host = make_a_host(words[index])
iterated_word_host.add(index)
current_result.append(words[index])
else:
continue
for i in range(index+1, len(words)):
if i in iterated_word_host:
continue
current_host = make_a_host(words[i])
if current_host == current_word_host:
current_result.append(words[i])
iterated_word_host.add(i)
anagram.append(current_result)
return anagram