Теодор обнови решението на 15.03.2014 15:26 (преди над 10 години)
+def is_pangram(pangram):
+ alphabet = ["а", "б", "в", "г", "д", "е", "ж", "з", "и", "й", "к", "л",
+ "м", "н", "о", "п", "р", "с", "т", "у", "ф", "х", "ц", "ч",
+ "ш", "щ", "ъ", "ь", "ю", "я"]
+ for letter in pangram.lower():
+ if letter in alphabet:
+ alphabet.remove(letter)
+ return not len(alphabet)
+
+
+def char_histogram(sentence):
+ number_of_appearances = {}
+ already_calculated = set()
+ for letter in sentence:
+ appeared = 1
+ if(not letter in already_calculated):
+ already_calculated.add(letter)
+ for i in range(sentence.find(letter) + 1, len(sentence)):
+ if sentence[i] == letter:
+ appeared += 1
+ number_of_appearances[letter] = appeared
+ return number_of_appearances
+
+
+def sort_by(criterion, to_sort):
+ for i in range(0, len(to_sort)):
+ for j in range(0, len(to_sort) - 1 - i):
+ if criterion(to_sort[j], to_sort[j + 1]) > 0:
+ to_sort[j], to_sort[j + 1] = to_sort[j + 1], to_sort[j]
+ return to_sort
+
+
+def group_by_type(mixed_types):
+ sorted_types = {}
+ same_type = {}
+ current_type = ""
+ for item in mixed_types:
+ for item_compare in mixed_types:
+ if type(item) == type(item_compare):
+ same_type[item_compare] = mixed_types.get(item_compare)
+ current_type = type(item_compare)
+ sorted_types[current_type] = same_type.copy()
+ same_type.clear()
+ return sorted_types
+
+
+def are_anagrams(word, anagram):
+ letters_word = [letter for letter in word]
+ letters_anagram = [letter for letter in anagram]
+ for letter in letters_word.copy():
+ if letter in letters_anagram:
+ letters_word.remove(letter)
+ letters_anagram.remove(letter)
+ return not(bool(len(letters_word)) or bool(len(letters_anagram)))
+
+
+def anagrams(words):
+ anagram_collected = []
+ anagram_sublist = []
+ anagrammed = set()
+ for sample in words:
+ for compare in words:
+ if are_anagrams(sample, compare) and not compare in anagrammed:
+ anagram_sublist.append(compare)
+ anagrammed.add(compare)
+ if len(anagram_sublist) != 0:
+ anagram_collected.append(anagram_sublist.copy())
+ anagram_sublist.clear()
+ return anagram_collected
- За анаграмите погледни във форумите и ще видиш, че искаме да има еднакви букви, но не държим и символите да са еднакви
- Опитай се да се възползваш повече от вградените неща в Python