Божидар обнови решението на 17.03.2014 12:57 (преди над 10 години)
+def is_pangram(sentence):
+ # Add all letters from the bulgarian alphabet(i is their unicode)
+ alphabet = set()
+ for i in range(1040, 1072):
+ alphabet.add(chr(i))
+ # remove each letter from sentence from the alphabet set
+ sentence.upper()
+ for letter in sentence:
+ alphabet.discard(letter)
+ # if no letters are left in the alphabet than all have been used
+ return alphabet == set()
+
+
+def char_histogram(text):
+ character_count = {}
+ for character in text:
+ if character in character_count:
+ character_count[character] += 1
+ else:
+ character_count[character] = 1
+
+ return character_count
+
+
+def sort_by(func, arguments):
+ # trivial check
+ if len(arguments) < 2:
+ return arguments
+
+ stop_iteration = False
+ while not stop_iteration:
+ stop_iteration = True
+ for i in range(len(arguments) - 1):
+ if func(arguments[i], arguments[i + 1]) > 0:
+ arguments[i], arguments[i + 1] = arguments[i + 1], arguments[i]
+ stop_iteration = False
+
+ return arguments
+
+
+def group_by_type(dictionary):
+ type_dictionary = {}
+ for key in dictionary.keys():
+ if type(key) not in type_dictionary:
+ type_dictionary[type(key)] = {}
+ type_dictionary[type(key)][key] = dictionary[key]
+
+ return type_dictionary
+
+
+def anagrams(words):
+ anagramatic_words = {}
+ for word in words:
+ letters = [letter for letter in word if letter.isalpha()]
+ letters.sort()
+ letters = tuple(letters)
+ if letters in anagramatic_words.keys():
+ anagramatic_words[letters].append(word)
+ else:
+ anagramatic_words[letters] = [word]
+
+ return list(anagramatic_words.values())