Владимир обнови решението на 17.03.2014 19:12 (преди над 10 години)
+BG_ALPHABET = "абвгдежзийклмнопрстуфхцчшщьъюя"
+EN_ALPHABET = "abcdefghijklmnopqrstuvwxyz"
+ALPHABET = BG_ALPHABET + EN_ALPHABET
+
+def is_pangram(sentence):
+ for symbol in BG_ALPHABET:
+ if symbol not in sentence.lower():
+ return False
+ return True
+
+
+def char_histogram(text):
+ histogram = {}
+ for symbol in text:
+ if symbol in histogram:
+ histogram[symbol] += 1
+ else:
+ histogram[symbol] = 1
+ return histogram
+
+
+def sort_by(func, arguments):
+ to_be_sorted = arguments.copy()
+ length = len(to_be_sorted)
+ for i in range(1, length):
+ j = i-1
+ val = to_be_sorted[i]
+ while j >= 0 and func( to_be_sorted[j], val) > 0:
+ to_be_sorted[j + 1] = to_be_sorted[j]
+ j -= 1
+ to_be_sorted[j+1] = val
+ return to_be_sorted
+
+
+def group_by_type(dictionary):
+ result = {}
+ for key in dictionary:
+ result.setdefault(type(key),{})[key] = dictionary[key]
+ return result
+
+
+def is_anagram(first, second):
+ first = first.lower()
+ second = second.lower()
+ first = [letter for letter in first if letter in ALPHABET]
+ second = [letter for letter in second if letter in ALPHABET]
+ first.sort()
+ second.sort()
+ return first == second
+
+def is_member(list_of_lists, elem):
+ for i in list_of_lists:
+ if elem in i:
+ return True
+ return False
+
+
+def anagrams(words):
+ result = []
+ tmp = []
+ for word in words:
+ tmp.clear()
+ if not is_member(result, word):
+ for other in words:
+ if is_anagram(word, other):
+ tmp.append(other)
+ if len(tmp):
+ result.append(list(tmp))
+ return result
Супер, но имената tmp
, val
, elem
и list_of_lists
не са особено описателни
Подходящо ли е тогава tmp= anagrams_of_one_word; val = to_insert; list_of_lists = double_nested; elem = element; ?