Решение на Пет функции от Атанас Филчев

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

Към профила на Атанас Филчев

Резултати

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

Код

from collections import defaultdict
from functools import cmp_to_key
def is_pangram(input_sentence):
BG_ALPHABET = set(['а', 'б', 'в', 'г', 'д', 'е', 'ж', 'з',
'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п',
'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч',
'ш', 'щ', 'ъ', 'ь', 'ю', 'я'])
sentence_chars = set()
for character in input_sentence.lower():
sentence_chars.add(character)
return len(BG_ALPHABET-sentence_chars) == 0
def char_histogram(input_text):
symbols_number = defaultdict(int)
for symbol in list(input_text):
symbols_number[symbol] += 1
return symbols_number
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(input_dict):
grouped_by_type = dict()
for key, value in input_dict.items():
grouped_by_type.setdefault(type(key), {})[key] = value
return grouped_by_type
def anagrams(input_words):
anagrams_to_return = []
input_words_lower = [word.lower() for word in input_words]
for word in input_words_lower:
anagrams_for_word = []
for possible_anagram in input_words:
if is_anagram(word, possible_anagram.lower()):
# remove the entry in the orig list
input_words = list(filter(lambda word:
word != possible_anagram.lower(),
input_words))
anagrams_for_word.append(possible_anagram)
anagrams_to_return.append(anagrams_for_word)
return list(filter(lambda anagram: len(anagram) > 0, anagrams_to_return))
def is_anagram(word, possible_anagram):
words = list(filter(lambda char: char.isalpha(), word))
words.sort()
possible_anagrams = list(filter(lambda char: char.isalpha(),
possible_anagram))
possible_anagrams.sort()
return words == possible_anagrams

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

................
----------------------------------------------------------------------
Ran 16 tests in 0.013s

OK

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

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

+def is_pangram(input_sentence):
+ bg_alphabet = set(['а', 'б', 'в', 'г', 'д', 'е', 'ж', 'з',
+ 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п',
+ 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч',
+ 'ш', 'щ', 'ъ', 'ь', 'ю', 'я'])
+ set_of_setnece_chars = set()
+
+ for ch in input_sentence:
+ set_of_setnece_chars.add(ch)
+
+ return len(bg_alphabet-set_of_setnece_chars) == 0
+
+
+def char_histogram(input_text):
+ symbols_number = defaultdict(int)
+ for symbol in list(input_text):
+ symbols_number[symbol] = symbols_number[symbol] + 1
+
+ return dict(symbols_number)
+
+
+def sort_by(func, arguments):
+ return sorted(arguments, key=cmp_to_key(func))
+
+
+def group_by_type(input_dict):
+
+ grouped_by_type = dict()
+ for key, value in input_dict.items():
+ if type(key) in grouped_by_type.keys():
+ grouped_by_type[type(key)][key] = value
+ else:
+ new_entry = {key: value}
+ grouped_by_type[type(key)] = new_entry
+
+ return grouped_by_type
+
+
+def anagrams(input_words):
+ anagrams_to_return = []
+
+ for word in input_words:
+ possible_anagrams = list(map("".join, itertools.permutations(word)))
+
+ anagrams_for_word = []
+ for anagram in possible_anagrams:
+ if anagram in input_words:
+ # remove the entry in the orig list
+ input_words = list(filter(lambda a: a != anagram, input_words))
+ anagrams_for_word.append(anagram)
+
+ anagrams_to_return.append(anagrams_for_word)
+
+ return list(filter(lambda a: len(a) > 0, anagrams_to_return))

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

+from collections import defaultdict
+from functools import cmp_to_key
+import itertools
+
+
def is_pangram(input_sentence):
- bg_alphabet = set(['а', 'б', 'в', 'г', 'д', 'е', 'ж', 'з',
+ BG_ALPHABET = set(['а', 'б', 'в', 'г', 'д', 'е', 'ж', 'з',
'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п',
'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч',
'ш', 'щ', 'ъ', 'ь', 'ю', 'я'])
- set_of_setnece_chars = set()
+ set_of_sentence_chars = set()
- for ch in input_sentence:
- set_of_setnece_chars.add(ch)
+ for character in input_sentence:
+ set_of_sentence_chars.add(character)
- return len(bg_alphabet-set_of_setnece_chars) == 0
+ return len(BG_ALPHABET-set_of_sentence_chars) == 0
def char_histogram(input_text):
symbols_number = defaultdict(int)
for symbol in list(input_text):
- symbols_number[symbol] = symbols_number[symbol] + 1
+ symbols_number[symbol] += 1
return dict(symbols_number)
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(input_dict):
grouped_by_type = dict()
for key, value in input_dict.items():
- if type(key) in grouped_by_type.keys():
- grouped_by_type[type(key)][key] = value
- else:
- new_entry = {key: value}
- grouped_by_type[type(key)] = new_entry
-
+ grouped_by_type.setdefault(type(key), {})[key] = value
return grouped_by_type
def anagrams(input_words):
anagrams_to_return = []
for word in input_words:
possible_anagrams = list(map("".join, itertools.permutations(word)))
anagrams_for_word = []
for anagram in possible_anagrams:
if anagram in input_words:
# remove the entry in the orig list
- input_words = list(filter(lambda a: a != anagram, input_words))
+ input_words = list(filter(lambda word: word != anagram,
+ input_words))
anagrams_for_word.append(anagram)
anagrams_to_return.append(anagrams_for_word)
- return list(filter(lambda a: len(a) > 0, anagrams_to_return))
+ return list(filter(lambda anagram: len(anagram) > 0, anagrams_to_return))
+

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

from collections import defaultdict
from functools import cmp_to_key
import itertools
def is_pangram(input_sentence):
BG_ALPHABET = set(['а', 'б', 'в', 'г', 'д', 'е', 'ж', 'з',
'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п',
'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч',
'ш', 'щ', 'ъ', 'ь', 'ю', 'я'])
set_of_sentence_chars = set()
- for character in input_sentence:
+ for character in input_sentence.lower():
set_of_sentence_chars.add(character)
return len(BG_ALPHABET-set_of_sentence_chars) == 0
def char_histogram(input_text):
symbols_number = defaultdict(int)
for symbol in list(input_text):
symbols_number[symbol] += 1
return dict(symbols_number)
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(input_dict):
grouped_by_type = dict()
for key, value in input_dict.items():
grouped_by_type.setdefault(type(key), {})[key] = value
return grouped_by_type
def anagrams(input_words):
anagrams_to_return = []
for word in input_words:
possible_anagrams = list(map("".join, itertools.permutations(word)))
anagrams_for_word = []
for anagram in possible_anagrams:
if anagram in input_words:
# remove the entry in the orig list
input_words = list(filter(lambda word: word != anagram,
input_words))
anagrams_for_word.append(anagram)
anagrams_to_return.append(anagrams_for_word)
return list(filter(lambda anagram: len(anagram) > 0, anagrams_to_return))
-

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

from collections import defaultdict
from functools import cmp_to_key
-import itertools
def is_pangram(input_sentence):
BG_ALPHABET = set(['а', 'б', 'в', 'г', 'д', 'е', 'ж', 'з',
'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п',
'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч',
'ш', 'щ', 'ъ', 'ь', 'ю', 'я'])
set_of_sentence_chars = set()
for character in input_sentence.lower():
set_of_sentence_chars.add(character)
return len(BG_ALPHABET-set_of_sentence_chars) == 0
def char_histogram(input_text):
symbols_number = defaultdict(int)
for symbol in list(input_text):
symbols_number[symbol] += 1
return dict(symbols_number)
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(input_dict):
grouped_by_type = dict()
for key, value in input_dict.items():
grouped_by_type.setdefault(type(key), {})[key] = value
return grouped_by_type
def anagrams(input_words):
anagrams_to_return = []
for word in input_words:
- possible_anagrams = list(map("".join, itertools.permutations(word)))
-
anagrams_for_word = []
- for anagram in possible_anagrams:
- if anagram in input_words:
+ for possible_anagram in input_words:
+ if is_anagram(word, possible_anagram):
# remove the entry in the orig list
- input_words = list(filter(lambda word: word != anagram,
+ input_words = list(filter(lambda word:
+ word != possible_anagram,
input_words))
- anagrams_for_word.append(anagram)
+ anagrams_for_word.append(possible_anagram)
anagrams_to_return.append(anagrams_for_word)
return list(filter(lambda anagram: len(anagram) > 0, anagrams_to_return))
+
+
+def is_anagram(word, possible_anagram):
+ word_list = list(word)
+ word_list.sort()
+ possible_anagram_list = list(possible_anagram)
+ possible_anagram_list.sort()
+
+ return word_list == possible_anagram_list

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

from collections import defaultdict
from functools import cmp_to_key
def is_pangram(input_sentence):
BG_ALPHABET = set(['а', 'б', 'в', 'г', 'д', 'е', 'ж', 'з',
'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п',
'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч',
'ш', 'щ', 'ъ', 'ь', 'ю', 'я'])
set_of_sentence_chars = set()
for character in input_sentence.lower():
set_of_sentence_chars.add(character)
return len(BG_ALPHABET-set_of_sentence_chars) == 0
def char_histogram(input_text):
symbols_number = defaultdict(int)
for symbol in list(input_text):
symbols_number[symbol] += 1
return dict(symbols_number)
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(input_dict):
grouped_by_type = dict()
for key, value in input_dict.items():
grouped_by_type.setdefault(type(key), {})[key] = value
return grouped_by_type
def anagrams(input_words):
anagrams_to_return = []
for word in input_words:
anagrams_for_word = []
for possible_anagram in input_words:
- if is_anagram(word, possible_anagram):
+ if is_anagram(word.lower(), possible_anagram.lower()):
# remove the entry in the orig list
input_words = list(filter(lambda word:
word != possible_anagram,
input_words))
anagrams_for_word.append(possible_anagram)
anagrams_to_return.append(anagrams_for_word)
return list(filter(lambda anagram: len(anagram) > 0, anagrams_to_return))
def is_anagram(word, possible_anagram):
word_list = list(word)
word_list.sort()
possible_anagram_list = list(possible_anagram)
possible_anagram_list.sort()
return word_list == possible_anagram_list

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

from collections import defaultdict
from functools import cmp_to_key
def is_pangram(input_sentence):
BG_ALPHABET = set(['а', 'б', 'в', 'г', 'д', 'е', 'ж', 'з',
'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п',
'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч',
'ш', 'щ', 'ъ', 'ь', 'ю', 'я'])
set_of_sentence_chars = set()
for character in input_sentence.lower():
set_of_sentence_chars.add(character)
return len(BG_ALPHABET-set_of_sentence_chars) == 0
def char_histogram(input_text):
symbols_number = defaultdict(int)
for symbol in list(input_text):
symbols_number[symbol] += 1
return dict(symbols_number)
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(input_dict):
grouped_by_type = dict()
for key, value in input_dict.items():
grouped_by_type.setdefault(type(key), {})[key] = value
return grouped_by_type
def anagrams(input_words):
anagrams_to_return = []
for word in input_words:
anagrams_for_word = []
for possible_anagram in input_words:
if is_anagram(word.lower(), possible_anagram.lower()):
# remove the entry in the orig list
input_words = list(filter(lambda word:
- word != possible_anagram,
+ word.lower() != possible_anagram.lower(),
input_words))
anagrams_for_word.append(possible_anagram)
anagrams_to_return.append(anagrams_for_word)
return list(filter(lambda anagram: len(anagram) > 0, anagrams_to_return))
def is_anagram(word, possible_anagram):
word_list = list(word)
word_list.sort()
possible_anagram_list = list(possible_anagram)
possible_anagram_list.sort()
return word_list == possible_anagram_list

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

from collections import defaultdict
from functools import cmp_to_key
def is_pangram(input_sentence):
BG_ALPHABET = set(['а', 'б', 'в', 'г', 'д', 'е', 'ж', 'з',
'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п',
'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч',
'ш', 'щ', 'ъ', 'ь', 'ю', 'я'])
set_of_sentence_chars = set()
for character in input_sentence.lower():
set_of_sentence_chars.add(character)
return len(BG_ALPHABET-set_of_sentence_chars) == 0
def char_histogram(input_text):
symbols_number = defaultdict(int)
for symbol in list(input_text):
symbols_number[symbol] += 1
return dict(symbols_number)
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(input_dict):
grouped_by_type = dict()
for key, value in input_dict.items():
grouped_by_type.setdefault(type(key), {})[key] = value
return grouped_by_type
def anagrams(input_words):
anagrams_to_return = []
+ input_words_lower = [word.lower() for word in input_words]
+ for word in input_words_lower:
- for word in input_words:
anagrams_for_word = []
for possible_anagram in input_words:
- if is_anagram(word.lower(), possible_anagram.lower()):
+ if is_anagram(word, possible_anagram.lower()):
# remove the entry in the orig list
input_words = list(filter(lambda word:
- word.lower() != possible_anagram.lower(),
+ word != possible_anagram.lower(),
input_words))
anagrams_for_word.append(possible_anagram)
anagrams_to_return.append(anagrams_for_word)
return list(filter(lambda anagram: len(anagram) > 0, anagrams_to_return))
def is_anagram(word, possible_anagram):
word_list = list(word)
word_list.sort()
possible_anagram_list = list(possible_anagram)
possible_anagram_list.sort()
return word_list == possible_anagram_list

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

from collections import defaultdict
from functools import cmp_to_key
def is_pangram(input_sentence):
BG_ALPHABET = set(['а', 'б', 'в', 'г', 'д', 'е', 'ж', 'з',
'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п',
'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч',
'ш', 'щ', 'ъ', 'ь', 'ю', 'я'])
set_of_sentence_chars = set()
for character in input_sentence.lower():
set_of_sentence_chars.add(character)
return len(BG_ALPHABET-set_of_sentence_chars) == 0
def char_histogram(input_text):
symbols_number = defaultdict(int)
for symbol in list(input_text):
symbols_number[symbol] += 1
return dict(symbols_number)
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(input_dict):
grouped_by_type = dict()
for key, value in input_dict.items():
grouped_by_type.setdefault(type(key), {})[key] = value
return grouped_by_type
def anagrams(input_words):
anagrams_to_return = []
input_words_lower = [word.lower() for word in input_words]
for word in input_words_lower:
-
anagrams_for_word = []
for possible_anagram in input_words:
if is_anagram(word, possible_anagram.lower()):
# remove the entry in the orig list
input_words = list(filter(lambda word:
word != possible_anagram.lower(),
input_words))
anagrams_for_word.append(possible_anagram)
anagrams_to_return.append(anagrams_for_word)
return list(filter(lambda anagram: len(anagram) > 0, anagrams_to_return))
def is_anagram(word, possible_anagram):
- word_list = list(word)
+ word_list = list(filter(lambda char: char.isalpha(), word))
word_list.sort()
- possible_anagram_list = list(possible_anagram)
+ possible_anagram_list = list(filter(lambda char: char.isalpha(),
+ possible_anagram))
possible_anagram_list.sort()
return word_list == possible_anagram_list

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

from collections import defaultdict
from functools import cmp_to_key
def is_pangram(input_sentence):
BG_ALPHABET = set(['а', 'б', 'в', 'г', 'д', 'е', 'ж', 'з',
'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п',
'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч',
'ш', 'щ', 'ъ', 'ь', 'ю', 'я'])
- set_of_sentence_chars = set()
+ sentence_chars = set()
for character in input_sentence.lower():
- set_of_sentence_chars.add(character)
+ sentence_chars.add(character)
- return len(BG_ALPHABET-set_of_sentence_chars) == 0
+ return len(BG_ALPHABET-sentence_chars) == 0
def char_histogram(input_text):
symbols_number = defaultdict(int)
for symbol in list(input_text):
symbols_number[symbol] += 1
- return dict(symbols_number)
+ return symbols_number
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(input_dict):
grouped_by_type = dict()
for key, value in input_dict.items():
grouped_by_type.setdefault(type(key), {})[key] = value
return grouped_by_type
def anagrams(input_words):
anagrams_to_return = []
input_words_lower = [word.lower() for word in input_words]
for word in input_words_lower:
anagrams_for_word = []
for possible_anagram in input_words:
if is_anagram(word, possible_anagram.lower()):
# remove the entry in the orig list
input_words = list(filter(lambda word:
word != possible_anagram.lower(),
input_words))
anagrams_for_word.append(possible_anagram)
anagrams_to_return.append(anagrams_for_word)
return list(filter(lambda anagram: len(anagram) > 0, anagrams_to_return))
def is_anagram(word, possible_anagram):
- word_list = list(filter(lambda char: char.isalpha(), word))
- word_list.sort()
- possible_anagram_list = list(filter(lambda char: char.isalpha(),
+ words = list(filter(lambda char: char.isalpha(), word))
+ words.sort()
+ possible_anagrams = list(filter(lambda char: char.isalpha(),
possible_anagram))
- possible_anagram_list.sort()
+ possible_anagrams.sort()
- return word_list == possible_anagram_list
+ return words == possible_anagrams