Александър обнови решението на 19.03.2014 02:01 (преди над 10 години)
+from collections import defaultdict
+
+LETTERS = 'абвгдежзийклмнопрстуфхкцчшщьюя'
+
+def is_pangram(text):
+ text_lowercase = text.lower()
+ for letter in LETTERS:
+ if letter not in text_lowercase:
+ return False
+ return True
+
+def char_histogram(text):
+ histogram = defaultdict(int)
+ for letter in text:
+ histogram[letter] += 1
+
+ return histogram
+
+def sort_by(func, arguments):
+ arguments_count = len(arguments)
+ sorted = list(arguments)
+ for i in range(1, arguments_count):
+ val = sorted[i]
+ j = i - 1
+ while (j >= 0) and func(sorted[j], val) > 0:
+ sorted[j+1] = sorted[j]
+ j = j - 1
+ sorted[j+1] = val
+
+ return sorted
+
+def group_by_type(dictionary):
+ types = defaultdict(dict)
+ for key in dictionary:
+ types[type(key)][key] = dictionary[key]
+
+ return dict(types)
+
+def anagrams(words):
+ matched_anagrams = defaultdict(list)
+ for word in words:
+ characters = set()
+ for letter in word:
+ if letter.isalpha():
+ characters.add(letter)
+ key = frozenset(characters)
+ matched_anagrams[key].append(word)
+
+ anagrams = []
+ for key in matched_anagrams:
+ anagrams.append(matched_anagrams[key])
+
+ return anagrams