Решение на Пет функции от Филип Митов

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

Към профила на Филип Митов

Резултати

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

Код

def is_pangram(sentence):
all_symbols = set()
for symbol in sentence:
if ord('А') <= ord(symbol) and ord(symbol) <= ord('я'):
all_symbols.add(symbol.lower())
return len(all_symbols) == 30
def char_histogram(text):
histogram_symbols = {}
for symbol in text:
if not symbol in histogram_symbols:
histogram_symbols.setdefault(symbol, 1)
else:
histogram_symbols[symbol] += 1
return histogram_symbols
def sort_by(func, arguments):
for outter_index in range(len(arguments)):
for index in range(len(arguments) - 1):
if func(arguments[index], arguments[index+1]) > 0:
arguments[index], arguments[index + 1] = arguments[index + 1],\
arguments[index]
return arguments
def group_by_type(dictionary):
grouped_types = {}
for key in dictionary:
if not type(key) in grouped_types:
grouped_types[type(key)] = {key: dictionary[key]}
else:
grouped_types[type(key)].update({key: dictionary[key]})
return grouped_types
def anagrams(words):
anagram_words = {}
for one_word in words:
key_symbols = [symbol.lower() for symbol in one_word \
if symbol.isalpha()]
key_symbols.sort()
key_symbols = str(key_symbols)
if not key_symbols in anagram_words:
anagram_words[key_symbols] = [one_word]
else:
anagram_words[key_symbols].append(one_word)
return list(anagram_words.values())

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

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

OK

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

Филип обнови решението на 17.03.2014 10:52 (преди над 10 години)

+def is_pangram(sentence):
+ all_symbols = set()
+ for symbol in sentence:
+ if ord('А') <= ord(symbol) and ord(symbol) <= ord('я'):
+ all_symbols.add(symbol.lower())
+
+ return len(all_symbols) == 30
+
+
+def char_histogram(text):
+ histogram_symbols = {}
+ for symbol in text:
+ if not symbol in histogram_symbols:
+ histogram_symbols.setdefault(symbol, 1)
+ else:
+ histogram_symbols[symbol] += 1
+
+ return histogram_symbols
+
+
+def sort_by(func, arguments):
+ for outter_index in range(len(arguments)):
+ for index in range(len(arguments) - 1):
+ if func(arguments[index], arguments[index+1]) > 0:
+ temp = arguments[index]
+ arguments[index] = arguments[index + 1]
+ arguments[index + 1] = temp
+
+ return arguments
+
+
+def group_by_type(dictionary):
+ grouped_types = {}
+ for key in dictionary:
+ if not type(key) in grouped_types:
+ grouped_types[type(key)] = {key: dictionary[key]}
+ else:
+ grouped_types[type(key)].update({key: dictionary[key]})
+
+ return grouped_types
+
+
+def anagrams(words):
+ anagram_words = {}
+ for one_word in words:
+ key_symbols = [symbol for symbol in one_word if symbol.isalpha()]
+ key_symbols.sort()
+ key_symbols = str(key_symbols)
+
+ if not key_symbols in anagram_words:
+ anagram_words[key_symbols] = [one_word]
+ else:
+ anagram_words[key_symbols].append(one_word)
+
+ return list(anagram_words.values())

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

def is_pangram(sentence):
all_symbols = set()
for symbol in sentence:
if ord('А') <= ord(symbol) and ord(symbol) <= ord('я'):
all_symbols.add(symbol.lower())
return len(all_symbols) == 30
-
def char_histogram(text):
histogram_symbols = {}
for symbol in text:
if not symbol in histogram_symbols:
histogram_symbols.setdefault(symbol, 1)
else:
histogram_symbols[symbol] += 1
return histogram_symbols
-
def sort_by(func, arguments):
for outter_index in range(len(arguments)):
for index in range(len(arguments) - 1):
if func(arguments[index], arguments[index+1]) > 0:
- temp = arguments[index]
- arguments[index] = arguments[index + 1]
- arguments[index + 1] = temp
+ arguments[index], arguments[index + 1] = arguments[index + 1],\
+ arguments[index]
return arguments
-
def group_by_type(dictionary):
grouped_types = {}
for key in dictionary:
if not type(key) in grouped_types:
grouped_types[type(key)] = {key: dictionary[key]}
else:
grouped_types[type(key)].update({key: dictionary[key]})
return grouped_types
-
def anagrams(words):
anagram_words = {}
for one_word in words:
key_symbols = [symbol for symbol in one_word if symbol.isalpha()]
key_symbols.sort()
key_symbols = str(key_symbols)
- if not key_symbols in anagram_words:
- anagram_words[key_symbols] = [one_word]
+ if not key_symbols.lower() in anagram_words:
+ anagram_words[key_symbols.lower()] = [one_word]
else:
- anagram_words[key_symbols].append(one_word)
+ anagram_words[key_symbols.lower()].append(one_word)
return list(anagram_words.values())

Филип обнови решението на 19.03.2014 01:03 (преди над 10 години)

def is_pangram(sentence):
all_symbols = set()
for symbol in sentence:
if ord('А') <= ord(symbol) and ord(symbol) <= ord('я'):
all_symbols.add(symbol.lower())
return len(all_symbols) == 30
def char_histogram(text):
histogram_symbols = {}
for symbol in text:
if not symbol in histogram_symbols:
histogram_symbols.setdefault(symbol, 1)
else:
histogram_symbols[symbol] += 1
return histogram_symbols
def sort_by(func, arguments):
for outter_index in range(len(arguments)):
for index in range(len(arguments) - 1):
if func(arguments[index], arguments[index+1]) > 0:
arguments[index], arguments[index + 1] = arguments[index + 1],\
arguments[index]
return arguments
def group_by_type(dictionary):
grouped_types = {}
for key in dictionary:
if not type(key) in grouped_types:
grouped_types[type(key)] = {key: dictionary[key]}
else:
grouped_types[type(key)].update({key: dictionary[key]})
return grouped_types
def anagrams(words):
anagram_words = {}
for one_word in words:
- key_symbols = [symbol for symbol in one_word if symbol.isalpha()]
+ key_symbols = [symbol.lower() for symbol in one_word \
+ if symbol.isalpha()]
+
key_symbols.sort()
key_symbols = str(key_symbols)
- if not key_symbols.lower() in anagram_words:
- anagram_words[key_symbols.lower()] = [one_word]
+ if not key_symbols in anagram_words:
+ anagram_words[key_symbols] = [one_word]
else:
- anagram_words[key_symbols.lower()].append(one_word)
+ anagram_words[key_symbols].append(one_word)
return list(anagram_words.values())