Теодор обнови решението на 19.03.2014 14:16 (преди над 10 години)
+def is_pangram(sentence):
+ bg_alphabet = {chr(1040+i) for i in range(32)}
+ used_letters = set()
+ for letter in sentence.upper():
+ if letter in bg_alphabet:
+ used_letters.add(letter)
+ return len(used_letters) == 30
+
+from collections import Counter
+def char_histogram(text):
+ dict_counter = Counter()
+ for letter in text:
+ dict_counter.update(Counter(letter))
+ return dict_counter
+
+
+def sort_by(func, arguments):
+ for i in range(len(arguments)-1):
+ for j in range(len(arguments)-1):
+ change = func(arguments[j], arguments[j+1])
+ if change > 0:
+ swap = arguments[j]
+ arguments[j] = arguments[j+1]
+ arguments[j+1] = swap
+ return arguments
+
+def group_by_type(dictionary):
+ dict_by_type = {}
+ for key, value in dictionary.items():
+ if type(key) in dict_by_type:
+ dict_by_type[type(key)].update({key:value})
+ else:
+ dict_by_type[type(key)] = {key:value}
+ return dict_by_type
+
+def anagrams(words):
+ hist_dict = {}
+
+ anagram_groups = list()
+ lenght_groups = list()
+ words.sort(key = len)
+ length_list = list()
+ for i in range(1, len(words)):
+ if len(words[i-1]) == len(words[i]):
+ length_list.append(words[i-1])
+ else:
+ length_list.append(words[i-1])
+ lenght_groups.append(length_list)
+ length_list = list()
+
+ repeating = list()
+ for words in lenght_groups:
+ for i in range(len(words)):
+ anagarm_list = list()
+ for j in range(len(words)):
+ if cmp(char_histogram(words[i]),char_histogram(words[j])):
+ anagram_list.append(words[j])
+ repeating.append(anagram_list)
+
+ return repeating