Любомир обнови решението на 16.03.2014 00:18 (преди над 10 години)
+from collections import defaultdict
+
+SAMPLE_SENTENCE = 'Ах, чудна българска земьо, полюшвай цъфтящи жита!'
+VALID_CHARS = {char for char in SAMPLE_SENTENCE.lower()
+ if ord('а') <= ord(char) <= ord('я')}
+
+
+def is_pangram(sentence):
+ return {char for char in sentence.lower()
+ if ord('а') <= ord(char) <= ord('я')} == VALID_CHARS
+
+
+def char_histogram(string):
+ histogram = defaultdict(int)
+ for char in string:
+ histogram[char] += 1
+
+ # defaultdict -> dict
+ return dict(histogram)
+
+
+def sort_by(predicate, array):
+ is_sorted = False
+ top = len(array)-1
+
+ while not is_sorted:
+ is_sorted = True
+ for c in range(0, top):
+ if predicate(array[c], array[c+1]) > 0:
+ array[c], array[c+1] = array[c+1], array[c]
+ is_sorted = False
+ top -= 1
+
+ return array
+
+
+def group_by_type(ungrouped):
+ grouped = defaultdict(lambda: defaultdict(int))
+ for key, item in ungrouped.items():
+ grouped[type(key)][key] = item
+
+ #defaultdict -> dict, nested
+ return dict(map(lambda item: (item[0], dict(item[1])), grouped.items()))
+
+
+def anagrams(words):
+ def to_anagram_hash(word):
+ return ''.join(sorted([char for char in word if char.isalpha()]))
+
+ anagram_table = defaultdict(list)
+ for word in words:
+ anagram_table[to_anagram_hash(word)].append(word)
+
+ #defaultdict -> list
+ return [list(values) for key, values in anagram_table.items()]