Стефан обнови решението на 17.03.2014 01:09 (преди над 10 години)
+CYRILLIC_ALPHABET = 'абвгдежзийклмнопрстуфхцчшщъьюя'
+
+def is_pangram(sentence):
+ for letter in CYRILLIC_ALPHABET:
+ if letter not in sentence and letter.upper() not in sentence:
+ return False
+ return True
+
+def char_histogram(text):
+ frequencies = { }
+ for char in text:
+ if char not in frequencies:
+ frequencies[char] = 1
+ else:
+ frequencies[char] = frequencies[char] + 1
+ return frequencies
+
+def sort_by(func, arguments):
+ sorted = arguments
+ for position in range(len(sorted)):
+ for counter in range(position, len(sorted)):
+ if func(sorted[position], sorted[counter]) > 0:
+ temp = sorted[position]
+ sorted[position] = sorted[counter]
+ sorted[counter] = temp
+ return sorted
+
+def group_by_type(dictionary):
+ groups = {}
+ for value in dictionary:
+ class_name = value.__class__
+ if class_name not in groups:
+ groups[class_name] = {}
+ groups[class_name][value] = dictionary[value]
+ return groups
+
+def letter_count(string):
+ words = string.split(' ')
+ merged_words = ''
+ for word in words:
+ merged_words = merged_words + word
+
+ return len(merged_words)
+
+def is_letter(symbol):
+ is_capital_latin = symbol > 'A' and symbol < 'Z'
+ is_latin = symbol > 'a' and symbol < 'z'
+ is_cyrillic = symbol.lower() in CYRILLIC_ALPHABET
+ return is_capital_latin or is_latin or is_cyrillic
+
+def anagram(word_1, word_2):
+ for symbol in word_1:
+ if is_letter(symbol) and symbol.lower() not in word_2.lower():
+ return False
+ for symbol in word_2:
+ if is_letter(symbol) and symbol.lower() not in word_1.lower():
+ return False
+ return True
+
+def anagrams(words):
+ result = []
+ added = False
+ for word in words:
+ added = False
+ for group in result:
+ if anagram(word, group[0]):
+ group.append(word)
+ added = True
+ if not added:
+ result.append([word])
+ return result
- Виж къде може да се издъни сортирането ти
- В Python размяната на стойностите става така:
a, b = b, a
- При създаването на празен речник не е нужно да оставяме интервал между скобите
- Името
first_word
е по-добро отword_1