Мария обнови решението на 19.03.2014 13:33 (преди над 10 години)
+def is_pangram(sentence):
+ alphabet = 'абвгдежзийклмнопрстуфхцчшщъьюя'
+ for char in alphabet:
+ if char not in sentence.lower():
+ return False
+ return True
+
+
+def char_histogram(text):
+ hist = {}
+ for char in text:
+ if char in hist.keys():
+ hist[char] += 1
+ else:
+ hist[char] = 1
+ return hist
+
+
+def sort_by(func, arguments):
+ for x in range(len(arguments) - 1):
+ for y in range(x,len(arguments)):
+ if func(arguments[x], arguments[y]) > 0:
+ arguments[x], arguments[y] = arguments[y], arguments[x]
+ return arguments
+
+
+def group_by_type(dictionary):
+ result = {}
+ for key, value in dictionary.items():
+ if type(key) not in result.keys():
+ result[type(key)] = {}
+ result[type(key)][key] = value
+ return result
+
+
+def are_anagrams(a, b):
+ dict_a = char_histogram(a)
+ dict_b = char_histogram(b)
+ return len(set(dict_a.items()) ^ set(dict_b.items())) == 0
+
+
+def anagrams(words):
+ result = []
+ for word in words:
+ word_is_anagram_of_group = False
+ for group in result:
+ if are_anagrams(word, group[0]):
+ group.append(word)
+ word_is_anagram_of_group = True
+ if not word_is_anagram_of_group:
+ result.append([word])
+ return result