Цветелина обнови решението на 14.03.2014 01:25 (преди над 10 години)
+def is_anagram(word, anagram):
+ same_chars = [char for char in word if char in word and char in anagram]
+ return len(same_chars) == len(word) == len(anagram)
+
+
+def anagrams(words):
+ grouped_words = []
+
+ for word in words:
+ added = False
+ for anagram_words in grouped_words:
+ if word not in anagram_words and is_anagram(word, anagram_words[0]):
+ anagram_words.append(word)
+ added = True
+ break
+ if not added:
+ grouped_words.append([word])
+
+ return grouped_words
+
+
+def group_by_type(dictionary):
+ grouped = {}
+ for key, value in dictionary.items():
+ if type(key) not in grouped:
+ grouped[type(key)] = {}
+ grouped[type(key)][key] = value
+ return grouped
+
+
+def sort_by(func, arguments):
+ for i in range(0, len(arguments) - 1):
+ if func(arguments[i], arguments[i + 1]) > 0:
+ arguments[i], arguments[i + 1] = arguments[i + 1], arguments[i]
+ return arguments
+
+
+def char_histogram(text):
+ return {char: text.count(char) for char in text}
+
+
+PUNCTUANTION_SYMBOLS = [' ', ',', '.', '!', '?', ';', ':', '\'', '"', '-']
+
+
+def is_pangram(sentence):
+ sentence = sentence.lower()
+ if len(sentence) < 30:
+ return False
+
+ all_leters = {chr(code) for code in range(1072, 1104) if code != 1101}
+ used_letters = set()
+ for letter in sentence:
+ if letter not in PUNCTUANTION_SYMBOLS and letter not in all_leters:
+ return False
+ elif letter in all_leters:
+ used_letters.add(letter)
+ return len(used_letters) == 30