Иван обнови решението на 18.03.2014 01:59 (преди над 10 години)
+from functools import cmp_to_key
+
+
+def is_pangram(sentence):
+ alphabet = [
+ 'а', 'б', 'в', 'г', 'д', 'е', 'ж', 'з',
+ 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п',
+ 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч',
+ 'ш', 'щ', 'ъ', 'ь', 'ю', 'я',
+ ]
+ count = 0
+ sentence = sentence.lower()
+ sentence = set(sentence)
+ for letter in alphabet:
+ if letter in sentence:
+ count += 1
+ if count == 30:
+ return True
+ else:
+ return False
+
+
+def char_histogram(text):
+ new_text = set(text)
+ new_text = tuple(text)
+ new_dict = {}
+ for symbol in new_text:
+ new_dict[symbol] = text.count(symbol)
+ return new_dict
+
+
+def sort_by(func, arguments):
+ return sorted(arguments, key=cmp_to_key(func))
+
+
+def group_by_type(dictionary):
+ new_dictionary = {}
+ for key in dictionary:
+ new_dictionary[type(key)] = {value: dictionary[value] for value in
+ dictionary if type(value) == type(key)}
+ return new_dictionary
+
+
+def check_characters(first_word, second_word):
+ characters = []
+ for number in range(97, 123):
+ characters.append(chr(number))
+ first_word = first_word.lower()
+ second_word = second_word.lower()
+ for word_1 in set(first_word):
+ if word_1 not in characters:
+ first_word = first_word.replace(word_1, '')
+ for word_2 in set(second_word):
+ if word_2 not in characters:
+ second_word = second_word.replace(word_2, '')
+ if sorted(first_word) == sorted(second_word):
+ return True
+ else:
+ return False
+
+
+def anagrams(words):
+ words.sort(key=len)
+ anagram_words = []
+ temporary_list = []
+ for first_word in range(len(words)):
+ for second_word in range(1, len(words)):
+ if words[first_word] != words[second_word]:
+ if check_characters(words[first_word], words[second_word]):
+ temporary_list.append(words[second_word])
+ words[second_word] = ''
+ temporary_list.append(words[first_word])
+ anagram_words.append(temporary_list)
+ temporary_list = []
+ while anagram_words.count(['']) != 0:
+ del anagram_words[anagram_words.index([''])]
+ return anagram_words
- Имената, които започват с
new_
не са особено добри - Ако използваш повече от вградените неща в езика, няма да ти се наложи да имаш имена като
word_1