Деян обнови решението на 18.03.2014 00:15 (преди над 10 години)
+from functools import cmp_to_key
+
+
+def is_pangram(sentence):
+ alphabet = set([
+ 'а', 'б', 'в', 'г', 'д', 'е', 'ж', 'з', 'и', 'й', 'к',
+ 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х',
+ 'ц', 'ч', 'ш', 'щ', 'ъ', 'ь', 'ю', 'я'
+ ])
+
+ for letter in sentence.lower():
+ if letter in alphabet:
+ alphabet.remove(letter)
+
+ return not alphabet
+
+
+def char_histogram(text):
+ histogram = {}
+
+ for character in text:
+ if character in histogram:
+ histogram[character] += 1
+ else:
+ histogram[character] = 1
+
+ return histogram
+
+
+def sort_by(func, arguments):
+ return sorted(arguments, key=cmp_to_key(func))
+
+
+def group_by_type(dictionary):
+ type_dictionary = {}
+
+ for key in dictionary.keys():
+ if type(key) not in type_dictionary:
+ type_dictionary[type(key)] = {key: dictionary[key]}
+ else:
+ type_dictionary[type(key)][key] = dictionary[key]
+
+ return type_dictionary
+
+
+def anagrams(words):
+ anagrams_collection = []
+
+ while words:
+ anagrams = find_anagrams(words[0], words)
+ anagrams_collection.append(anagrams)
+ words = clear_anagrams(words[0], words)
+
+ return anagrams_collection
+
+
+def find_anagrams(anagram, words):
+ anagrams = []
+
+ for word in words:
+ if are_anagrams(anagram, word):
+ anagrams.append(word)
+
+ return anagrams
+
+
+def clear_anagrams(anagram, words):
+ new_words = []
+
+ for word in words:
+ if not are_anagrams(anagram, word):
+ new_words.append(word)
+
+ return new_words
+
+
+def are_anagrams(first_phrase, second_phrase):
+ second_phrase = second_phrase.lower()
+
+ for symbol in first_phrase.lower():
+ second_phrase = second_phrase.replace(symbol, '', 1)
+ for symbol in second_phrase:
+ if symbol.isalpha():
+ return False
+
+ return True
Супер, но името new_words
може да стане по-описателно, а и можеш да използваш повече от вградените неща вместо цикли