Решение на Пет функции от Цветелина Борисова

Обратно към всички решения

Към профила на Цветелина Борисова

Резултати

  • 9 точки от тестове
  • 0 бонус точки
  • 9 точки общо
  • 15 успешни тест(а)
  • 1 неуспешни тест(а)

Код

def char_histogram(text):
return {char: text.count(char) for char in text}
def is_anagram(word, subject):
word_histogram = char_histogram(word.lower())
subject_histogram = char_histogram(subject.lower())
for key, value in word_histogram.items():
if key.isalpha():
if subject_histogram.get(key, -1) != value:
return False
return True
def anagrams(words):
grouped_words = []
for word in words:
added = False
for anagram_words in grouped_words:
if is_anagram(word, anagram_words[0]):
anagram_words.append(word)
added = True
break
if not added:
grouped_words.append([word])
return grouped_words
def group_by_type(dictionary):
grouped = {}
for key, value in dictionary.items():
if type(key) not in grouped:
grouped[type(key)] = {}
grouped[type(key)][key] = value
return grouped
def sort_by(func, arguments):
sorted_args = arguments
for i in range(0, len(arguments) - 1):
k = i
for j in range(i+1, len(arguments)):
if(func(sorted_args[k], sorted_args[j])) > 0:
k = j
sorted_args[i], sorted_args[k] = sorted_args[k], sorted_args[i]
return sorted_args
ALPHABET_LETTERS_COUNT = 30
def is_cyrilic(char_code):
return char_code in range(1072, 1104) and char_code not in (1101, 1099)
def is_pangram(sentence):
sentence = sentence.lower()
if len(sentence) < ALPHABET_LETTERS_COUNT:
return False
cyrilic_letters = set(char for char in sentence if is_cyrilic(ord(char)))
return len(cyrilic_letters) == ALPHABET_LETTERS_COUNT

Лог от изпълнението

...............F
======================================================================
FAIL: test_sort_by_simple_test (test.TestSortBy)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140319-21201-1rqw4xi/test.py", line 54, in test_sort_by_simple_test
    solution.sort_by(lambda x, y: x % 2 - y % 2, [0, 1, 2, 3, 4, 5]))
AssertionError: Lists differ: [0, 2, 4, 1, 3, 5] != [0, 2, 4, 3, 1, 5]

First differing element 3:
1
3

- [0, 2, 4, 1, 3, 5]
?              ---

+ [0, 2, 4, 3, 1, 5]
?           +++


----------------------------------------------------------------------
Ran 16 tests in 0.015s

FAILED (failures=1)

История (14 версии и 2 коментара)

Цветелина обнови решението на 14.03.2014 01:25 (преди над 10 години)

+def is_anagram(word, anagram):
+ same_chars = [char for char in word if char in word and char in anagram]
+ return len(same_chars) == len(word) == len(anagram)
+
+
+def anagrams(words):
+ grouped_words = []
+
+ for word in words:
+ added = False
+ for anagram_words in grouped_words:
+ if word not in anagram_words and is_anagram(word, anagram_words[0]):
+ anagram_words.append(word)
+ added = True
+ break
+ if not added:
+ grouped_words.append([word])
+
+ return grouped_words
+
+
+def group_by_type(dictionary):
+ grouped = {}
+ for key, value in dictionary.items():
+ if type(key) not in grouped:
+ grouped[type(key)] = {}
+ grouped[type(key)][key] = value
+ return grouped
+
+
+def sort_by(func, arguments):
+ for i in range(0, len(arguments) - 1):
+ if func(arguments[i], arguments[i + 1]) > 0:
+ arguments[i], arguments[i + 1] = arguments[i + 1], arguments[i]
+ return arguments
+
+
+def char_histogram(text):
+ return {char: text.count(char) for char in text}
+
+
+PUNCTUANTION_SYMBOLS = [' ', ',', '.', '!', '?', ';', ':', '\'', '"', '-']
+
+
+def is_pangram(sentence):
+ sentence = sentence.lower()
+ if len(sentence) < 30:
+ return False
+
+ all_leters = {chr(code) for code in range(1072, 1104) if code != 1101}
+ used_letters = set()
+ for letter in sentence:
+ if letter not in PUNCTUANTION_SYMBOLS and letter not in all_leters:
+ return False
+ elif letter in all_leters:
+ used_letters.add(letter)
+ return len(used_letters) == 30

Цветелина обнови решението на 14.03.2014 01:35 (преди над 10 години)

def is_anagram(word, anagram):
same_chars = [char for char in word if char in word and char in anagram]
return len(same_chars) == len(word) == len(anagram)
def anagrams(words):
grouped_words = []
for word in words:
added = False
for anagram_words in grouped_words:
if word not in anagram_words and is_anagram(word, anagram_words[0]):
anagram_words.append(word)
added = True
break
if not added:
grouped_words.append([word])
return grouped_words
def group_by_type(dictionary):
grouped = {}
for key, value in dictionary.items():
if type(key) not in grouped:
grouped[type(key)] = {}
grouped[type(key)][key] = value
return grouped
def sort_by(func, arguments):
for i in range(0, len(arguments) - 1):
if func(arguments[i], arguments[i + 1]) > 0:
arguments[i], arguments[i + 1] = arguments[i + 1], arguments[i]
return arguments
def char_histogram(text):
return {char: text.count(char) for char in text}
PUNCTUANTION_SYMBOLS = [' ', ',', '.', '!', '?', ';', ':', '\'', '"', '-']
+ALPHABET_LETTERS_COUNT = 30
-
def is_pangram(sentence):
sentence = sentence.lower()
- if len(sentence) < 30:
+ if len(sentence) < ALPHABET_LETTERS_COUNT:
return False
- all_leters = {chr(code) for code in range(1072, 1104) if code != 1101}
+ all_leters = {chr(code) for code in range(1072, 1104) if code not in [1101, 1099]}
used_letters = set()
for letter in sentence:
if letter not in PUNCTUANTION_SYMBOLS and letter not in all_leters:
return False
elif letter in all_leters:
used_letters.add(letter)
- return len(used_letters) == 30
+ return len(used_letters) == ALPHABET_LETTERS_COUNT

Цветелина обнови решението на 15.03.2014 01:13 (преди над 10 години)

+import string
+
+
def is_anagram(word, anagram):
- same_chars = [char for char in word if char in word and char in anagram]
- return len(same_chars) == len(word) == len(anagram)
+ if len(word) != len(anagram):
+ return False
+ matching_chars = [char for char in word if char in anagram]
+ return len(matching_chars) == len(word) == len(anagram)
def anagrams(words):
grouped_words = []
for word in words:
added = False
for anagram_words in grouped_words:
if word not in anagram_words and is_anagram(word, anagram_words[0]):
anagram_words.append(word)
added = True
break
if not added:
grouped_words.append([word])
return grouped_words
def group_by_type(dictionary):
grouped = {}
+
for key, value in dictionary.items():
if type(key) not in grouped:
grouped[type(key)] = {}
grouped[type(key)][key] = value
+
return grouped
def sort_by(func, arguments):
for i in range(0, len(arguments) - 1):
if func(arguments[i], arguments[i + 1]) > 0:
arguments[i], arguments[i + 1] = arguments[i + 1], arguments[i]
+
return arguments
def char_histogram(text):
return {char: text.count(char) for char in text}
-PUNCTUANTION_SYMBOLS = [' ', ',', '.', '!', '?', ';', ':', '\'', '"', '-']
ALPHABET_LETTERS_COUNT = 30
+
+def is_cyrilic(char_code):
+ return char_code in range(1072, 1104) and char_code not in [1101, 1099]
+
+
def is_pangram(sentence):
sentence = sentence.lower()
+
if len(sentence) < ALPHABET_LETTERS_COUNT:
return False
- all_leters = {chr(code) for code in range(1072, 1104) if code not in [1101, 1099]}
- used_letters = set()
+ used_words = set()
+ all_punctuation = string.punctuation + ' '
+
for letter in sentence:
- if letter not in PUNCTUANTION_SYMBOLS and letter not in all_leters:
+ if is_cyrilic(ord(letter)):
+ used_words.add(letter)
+ elif letter not in all_punctuation:
return False
- elif letter in all_leters:
- used_letters.add(letter)
+
- return len(used_letters) == ALPHABET_LETTERS_COUNT
+ return len(used_words) == ALPHABET_LETTERS_COUNT

Цветелина обнови решението на 15.03.2014 01:44 (преди над 10 години)

import string
def is_anagram(word, anagram):
if len(word) != len(anagram):
return False
matching_chars = [char for char in word if char in anagram]
return len(matching_chars) == len(word) == len(anagram)
def anagrams(words):
grouped_words = []
for word in words:
added = False
for anagram_words in grouped_words:
if word not in anagram_words and is_anagram(word, anagram_words[0]):
anagram_words.append(word)
added = True
break
if not added:
grouped_words.append([word])
return grouped_words
def group_by_type(dictionary):
grouped = {}
for key, value in dictionary.items():
if type(key) not in grouped:
grouped[type(key)] = {}
grouped[type(key)][key] = value
return grouped
def sort_by(func, arguments):
for i in range(0, len(arguments) - 1):
if func(arguments[i], arguments[i + 1]) > 0:
arguments[i], arguments[i + 1] = arguments[i + 1], arguments[i]
return arguments
def char_histogram(text):
return {char: text.count(char) for char in text}
ALPHABET_LETTERS_COUNT = 30
def is_cyrilic(char_code):
return char_code in range(1072, 1104) and char_code not in [1101, 1099]
def is_pangram(sentence):
sentence = sentence.lower()
if len(sentence) < ALPHABET_LETTERS_COUNT:
return False
- used_words = set()
- all_punctuation = string.punctuation + ' '
+ cyrilic_words = set(char for char in sentence if is_cyrilic(ord(char)))
- for letter in sentence:
- if is_cyrilic(ord(letter)):
+ return len(cyrilic_words) == ALPHABET_LETTERS_COUNT
- used_words.add(letter)
- elif letter not in all_punctuation:
- return False
-
- return len(used_words) == ALPHABET_LETTERS_COUNT

Цветелина обнови решението на 15.03.2014 01:46 (преди над 10 години)

import string
def is_anagram(word, anagram):
if len(word) != len(anagram):
return False
matching_chars = [char for char in word if char in anagram]
- return len(matching_chars) == len(word) == len(anagram)
+ return len(matching_chars) == len(word)
def anagrams(words):
grouped_words = []
for word in words:
added = False
for anagram_words in grouped_words:
if word not in anagram_words and is_anagram(word, anagram_words[0]):
anagram_words.append(word)
added = True
break
if not added:
grouped_words.append([word])
return grouped_words
def group_by_type(dictionary):
grouped = {}
for key, value in dictionary.items():
if type(key) not in grouped:
grouped[type(key)] = {}
grouped[type(key)][key] = value
return grouped
def sort_by(func, arguments):
for i in range(0, len(arguments) - 1):
if func(arguments[i], arguments[i + 1]) > 0:
arguments[i], arguments[i + 1] = arguments[i + 1], arguments[i]
return arguments
def char_histogram(text):
return {char: text.count(char) for char in text}
ALPHABET_LETTERS_COUNT = 30
def is_cyrilic(char_code):
return char_code in range(1072, 1104) and char_code not in [1101, 1099]
def is_pangram(sentence):
sentence = sentence.lower()
if len(sentence) < ALPHABET_LETTERS_COUNT:
return False
cyrilic_words = set(char for char in sentence if is_cyrilic(ord(char)))
return len(cyrilic_words) == ALPHABET_LETTERS_COUNT

Цветелина обнови решението на 15.03.2014 13:30 (преди над 10 години)

-import string
-
-
def is_anagram(word, anagram):
if len(word) != len(anagram):
return False
matching_chars = [char for char in word if char in anagram]
return len(matching_chars) == len(word)
def anagrams(words):
grouped_words = []
for word in words:
added = False
for anagram_words in grouped_words:
if word not in anagram_words and is_anagram(word, anagram_words[0]):
anagram_words.append(word)
added = True
break
if not added:
grouped_words.append([word])
return grouped_words
def group_by_type(dictionary):
grouped = {}
for key, value in dictionary.items():
if type(key) not in grouped:
grouped[type(key)] = {}
grouped[type(key)][key] = value
return grouped
def sort_by(func, arguments):
for i in range(0, len(arguments) - 1):
if func(arguments[i], arguments[i + 1]) > 0:
arguments[i], arguments[i + 1] = arguments[i + 1], arguments[i]
return arguments
def char_histogram(text):
return {char: text.count(char) for char in text}
ALPHABET_LETTERS_COUNT = 30
-def is_cyrilic(char_code):
+def is_cyrillic(char_code):
return char_code in range(1072, 1104) and char_code not in [1101, 1099]
def is_pangram(sentence):
sentence = sentence.lower()
if len(sentence) < ALPHABET_LETTERS_COUNT:
return False
- cyrilic_words = set(char for char in sentence if is_cyrilic(ord(char)))
+ cyrillic_letters = set(char for char in sentence if is_cyrillic(ord(char)))
- return len(cyrilic_words) == ALPHABET_LETTERS_COUNT
+ return len(cyrillic_letters) == ALPHABET_LETTERS_COUNT

Цветелина обнови решението на 15.03.2014 19:34 (преди над 10 години)

def is_anagram(word, anagram):
if len(word) != len(anagram):
return False
matching_chars = [char for char in word if char in anagram]
return len(matching_chars) == len(word)
def anagrams(words):
grouped_words = []
for word in words:
added = False
for anagram_words in grouped_words:
+ word = word.lower()
if word not in anagram_words and is_anagram(word, anagram_words[0]):
anagram_words.append(word)
added = True
break
if not added:
grouped_words.append([word])
return grouped_words
def group_by_type(dictionary):
grouped = {}
for key, value in dictionary.items():
if type(key) not in grouped:
grouped[type(key)] = {}
grouped[type(key)][key] = value
return grouped
def sort_by(func, arguments):
for i in range(0, len(arguments) - 1):
if func(arguments[i], arguments[i + 1]) > 0:
arguments[i], arguments[i + 1] = arguments[i + 1], arguments[i]
return arguments
def char_histogram(text):
return {char: text.count(char) for char in text}
ALPHABET_LETTERS_COUNT = 30
def is_cyrillic(char_code):
return char_code in range(1072, 1104) and char_code not in [1101, 1099]
def is_pangram(sentence):
sentence = sentence.lower()
if len(sentence) < ALPHABET_LETTERS_COUNT:
return False
cyrillic_letters = set(char for char in sentence if is_cyrillic(ord(char)))
return len(cyrillic_letters) == ALPHABET_LETTERS_COUNT

Анаграма е дума или фраза образувана от буквите на друга дума или фраза, чрез пермутация.

  • Твоето решение не прави разлика между буква и символ.
  • Опитай се да намериш случай, в който твоят sort_by се дъни

Цветелина обнови решението на 16.03.2014 13:20 (преди над 10 години)

-def is_anagram(word, anagram):
- if len(word) != len(anagram):
+def is_anagram(word, subject):
+ if len(word) != len(subject):
return False
- matching_chars = [char for char in word if char in anagram]
- return len(matching_chars) == len(word)
+ word_histogram = char_histogram(word)
+ subject_histogram = char_histogram(subject)
+ for key, value in word_histogram.items():
+ if key not in subject_histogram.keys():
+ return False
+ elif subject_histogram[key] != word_histogram[key]:
+ return False
+ return True
+
def anagrams(words):
grouped_words = []
for word in words:
added = False
for anagram_words in grouped_words:
word = word.lower()
if word not in anagram_words and is_anagram(word, anagram_words[0]):
anagram_words.append(word)
added = True
break
if not added:
grouped_words.append([word])
return grouped_words
def group_by_type(dictionary):
grouped = {}
for key, value in dictionary.items():
if type(key) not in grouped:
grouped[type(key)] = {}
grouped[type(key)][key] = value
return grouped
def sort_by(func, arguments):
+ sorted_args = arguments
+
for i in range(0, len(arguments) - 1):
- if func(arguments[i], arguments[i + 1]) > 0:
- arguments[i], arguments[i + 1] = arguments[i + 1], arguments[i]
+ k = i
+ for j in range(i+1, len(arguments)):
+ if(func(sorted_args[k], sorted_args[j])) > 0:
+ k = j
+ sorted_args[i], sorted_args[k] = sorted_args[k], sorted_args[i]
- return arguments
+ return sorted_args
def char_histogram(text):
return {char: text.count(char) for char in text}
ALPHABET_LETTERS_COUNT = 30
def is_cyrillic(char_code):
return char_code in range(1072, 1104) and char_code not in [1101, 1099]
def is_pangram(sentence):
sentence = sentence.lower()
if len(sentence) < ALPHABET_LETTERS_COUNT:
return False
cyrillic_letters = set(char for char in sentence if is_cyrillic(ord(char)))
return len(cyrillic_letters) == ALPHABET_LETTERS_COUNT

Цветелина обнови решението на 16.03.2014 15:51 (преди над 10 години)

+import string
+
+
+def char_histogram(text):
+ return {char: text.count(char) for char in text}
+
+
def is_anagram(word, subject):
if len(word) != len(subject):
return False
word_histogram = char_histogram(word)
subject_histogram = char_histogram(subject)
for key, value in word_histogram.items():
- if key not in subject_histogram.keys():
- return False
- elif subject_histogram[key] != word_histogram[key]:
- return False
+ if key not in string.punctuation + ' ':
+ if key not in subject_histogram.keys():
+ return False
return True
def anagrams(words):
grouped_words = []
for word in words:
added = False
for anagram_words in grouped_words:
- word = word.lower()
- if word not in anagram_words and is_anagram(word, anagram_words[0]):
+ if is_anagram(word.lower(), anagram_words[0].lower()):
anagram_words.append(word)
added = True
break
if not added:
grouped_words.append([word])
return grouped_words
def group_by_type(dictionary):
grouped = {}
for key, value in dictionary.items():
if type(key) not in grouped:
grouped[type(key)] = {}
grouped[type(key)][key] = value
return grouped
def sort_by(func, arguments):
sorted_args = arguments
for i in range(0, len(arguments) - 1):
k = i
for j in range(i+1, len(arguments)):
if(func(sorted_args[k], sorted_args[j])) > 0:
k = j
sorted_args[i], sorted_args[k] = sorted_args[k], sorted_args[i]
return sorted_args
-def char_histogram(text):
- return {char: text.count(char) for char in text}
-
-
ALPHABET_LETTERS_COUNT = 30
-def is_cyrillic(char_code):
- return char_code in range(1072, 1104) and char_code not in [1101, 1099]
+def is_cyrilic(char_code):
+ return char_code in range(1072, 1104) and char_code not in (1101, 1099)
def is_pangram(sentence):
sentence = sentence.lower()
if len(sentence) < ALPHABET_LETTERS_COUNT:
return False
- cyrillic_letters = set(char for char in sentence if is_cyrillic(ord(char)))
+ cyrilic_letters = set(char for char in sentence if is_cyrilic(ord(char)))
- return len(cyrillic_letters) == ALPHABET_LETTERS_COUNT
+ return len(cyrilic_letters) == ALPHABET_LETTERS_COUNT

Цветелина обнови решението на 16.03.2014 17:05 (преди над 10 години)

-import string
+from string import punctuation
def char_histogram(text):
return {char: text.count(char) for char in text}
def is_anagram(word, subject):
if len(word) != len(subject):
return False
word_histogram = char_histogram(word)
subject_histogram = char_histogram(subject)
for key, value in word_histogram.items():
- if key not in string.punctuation + ' ':
+ if key not in punctuation + ' ':
if key not in subject_histogram.keys():
return False
return True
def anagrams(words):
grouped_words = []
for word in words:
added = False
for anagram_words in grouped_words:
if is_anagram(word.lower(), anagram_words[0].lower()):
anagram_words.append(word)
added = True
break
if not added:
grouped_words.append([word])
return grouped_words
def group_by_type(dictionary):
grouped = {}
for key, value in dictionary.items():
if type(key) not in grouped:
grouped[type(key)] = {}
grouped[type(key)][key] = value
return grouped
def sort_by(func, arguments):
sorted_args = arguments
for i in range(0, len(arguments) - 1):
k = i
for j in range(i+1, len(arguments)):
if(func(sorted_args[k], sorted_args[j])) > 0:
k = j
sorted_args[i], sorted_args[k] = sorted_args[k], sorted_args[i]
return sorted_args
ALPHABET_LETTERS_COUNT = 30
def is_cyrilic(char_code):
return char_code in range(1072, 1104) and char_code not in (1101, 1099)
def is_pangram(sentence):
sentence = sentence.lower()
if len(sentence) < ALPHABET_LETTERS_COUNT:
return False
cyrilic_letters = set(char for char in sentence if is_cyrilic(ord(char)))
return len(cyrilic_letters) == ALPHABET_LETTERS_COUNT

Цветелина обнови решението на 16.03.2014 19:59 (преди над 10 години)

from string import punctuation
def char_histogram(text):
return {char: text.count(char) for char in text}
def is_anagram(word, subject):
if len(word) != len(subject):
return False
- word_histogram = char_histogram(word)
- subject_histogram = char_histogram(subject)
- for key, value in word_histogram.items():
- if key not in punctuation + ' ':
- if key not in subject_histogram.keys():
+ for letter in word:
+ if letter not in punctuation + ' ':
+ if letter not in subject:
return False
return True
def anagrams(words):
grouped_words = []
for word in words:
added = False
for anagram_words in grouped_words:
if is_anagram(word.lower(), anagram_words[0].lower()):
anagram_words.append(word)
added = True
break
if not added:
grouped_words.append([word])
return grouped_words
def group_by_type(dictionary):
grouped = {}
for key, value in dictionary.items():
if type(key) not in grouped:
grouped[type(key)] = {}
grouped[type(key)][key] = value
return grouped
def sort_by(func, arguments):
sorted_args = arguments
for i in range(0, len(arguments) - 1):
k = i
for j in range(i+1, len(arguments)):
if(func(sorted_args[k], sorted_args[j])) > 0:
k = j
sorted_args[i], sorted_args[k] = sorted_args[k], sorted_args[i]
return sorted_args
ALPHABET_LETTERS_COUNT = 30
def is_cyrilic(char_code):
return char_code in range(1072, 1104) and char_code not in (1101, 1099)
def is_pangram(sentence):
sentence = sentence.lower()
if len(sentence) < ALPHABET_LETTERS_COUNT:
return False
cyrilic_letters = set(char for char in sentence if is_cyrilic(ord(char)))
return len(cyrilic_letters) == ALPHABET_LETTERS_COUNT

Цветелина обнови решението на 19.03.2014 13:03 (преди над 10 години)

-from string import punctuation
-
-
def char_histogram(text):
return {char: text.count(char) for char in text}
def is_anagram(word, subject):
- if len(word) != len(subject):
- return False
+ word_histogram = char_histogram(word.lower())
+ subject_histogram = char_histogram(subject.lower())
- for letter in word:
- if letter not in punctuation + ' ':
- if letter not in subject:
+ for key, value in word_histogram.items():
+ if key.isalnum():
+ if key not in subject_histogram.keys():
return False
+ if subject_histogram[key] != value:
+ return False
return True
def anagrams(words):
grouped_words = []
for word in words:
added = False
for anagram_words in grouped_words:
- if is_anagram(word.lower(), anagram_words[0].lower()):
+ if is_anagram(word, anagram_words[0]):
anagram_words.append(word)
added = True
break
if not added:
grouped_words.append([word])
return grouped_words
def group_by_type(dictionary):
grouped = {}
for key, value in dictionary.items():
if type(key) not in grouped:
grouped[type(key)] = {}
grouped[type(key)][key] = value
return grouped
def sort_by(func, arguments):
sorted_args = arguments
for i in range(0, len(arguments) - 1):
k = i
for j in range(i+1, len(arguments)):
if(func(sorted_args[k], sorted_args[j])) > 0:
k = j
sorted_args[i], sorted_args[k] = sorted_args[k], sorted_args[i]
return sorted_args
ALPHABET_LETTERS_COUNT = 30
def is_cyrilic(char_code):
return char_code in range(1072, 1104) and char_code not in (1101, 1099)
def is_pangram(sentence):
sentence = sentence.lower()
if len(sentence) < ALPHABET_LETTERS_COUNT:
return False
cyrilic_letters = set(char for char in sentence if is_cyrilic(ord(char)))
return len(cyrilic_letters) == ALPHABET_LETTERS_COUNT

Цветелина обнови решението на 19.03.2014 14:13 (преди над 10 години)

def char_histogram(text):
return {char: text.count(char) for char in text}
def is_anagram(word, subject):
word_histogram = char_histogram(word.lower())
subject_histogram = char_histogram(subject.lower())
for key, value in word_histogram.items():
- if key.isalnum():
+ if key.isalpha():
if key not in subject_histogram.keys():
return False
if subject_histogram[key] != value:
return False
return True
def anagrams(words):
grouped_words = []
for word in words:
added = False
for anagram_words in grouped_words:
if is_anagram(word, anagram_words[0]):
anagram_words.append(word)
added = True
break
if not added:
grouped_words.append([word])
return grouped_words
def group_by_type(dictionary):
grouped = {}
for key, value in dictionary.items():
if type(key) not in grouped:
grouped[type(key)] = {}
grouped[type(key)][key] = value
return grouped
def sort_by(func, arguments):
sorted_args = arguments
for i in range(0, len(arguments) - 1):
k = i
for j in range(i+1, len(arguments)):
if(func(sorted_args[k], sorted_args[j])) > 0:
k = j
sorted_args[i], sorted_args[k] = sorted_args[k], sorted_args[i]
return sorted_args
ALPHABET_LETTERS_COUNT = 30
def is_cyrilic(char_code):
return char_code in range(1072, 1104) and char_code not in (1101, 1099)
def is_pangram(sentence):
sentence = sentence.lower()
if len(sentence) < ALPHABET_LETTERS_COUNT:
return False
cyrilic_letters = set(char for char in sentence if is_cyrilic(ord(char)))
return len(cyrilic_letters) == ALPHABET_LETTERS_COUNT

Цветелина обнови решението на 19.03.2014 16:34 (преди над 10 години)

def char_histogram(text):
return {char: text.count(char) for char in text}
def is_anagram(word, subject):
word_histogram = char_histogram(word.lower())
subject_histogram = char_histogram(subject.lower())
for key, value in word_histogram.items():
if key.isalpha():
- if key not in subject_histogram.keys():
- return False
- if subject_histogram[key] != value:
- return False
+ if subject_histogram.get(key, -1) != value:
+ return False
+
return True
def anagrams(words):
grouped_words = []
for word in words:
added = False
for anagram_words in grouped_words:
if is_anagram(word, anagram_words[0]):
anagram_words.append(word)
added = True
break
if not added:
grouped_words.append([word])
return grouped_words
def group_by_type(dictionary):
grouped = {}
for key, value in dictionary.items():
if type(key) not in grouped:
grouped[type(key)] = {}
grouped[type(key)][key] = value
return grouped
def sort_by(func, arguments):
sorted_args = arguments
for i in range(0, len(arguments) - 1):
k = i
for j in range(i+1, len(arguments)):
if(func(sorted_args[k], sorted_args[j])) > 0:
k = j
sorted_args[i], sorted_args[k] = sorted_args[k], sorted_args[i]
return sorted_args
ALPHABET_LETTERS_COUNT = 30
def is_cyrilic(char_code):
return char_code in range(1072, 1104) and char_code not in (1101, 1099)
def is_pangram(sentence):
sentence = sentence.lower()
if len(sentence) < ALPHABET_LETTERS_COUNT:
return False
cyrilic_letters = set(char for char in sentence if is_cyrilic(ord(char)))
return len(cyrilic_letters) == ALPHABET_LETTERS_COUNT