Решение на Пет функции от Моника Ефтимова

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

Към профила на Моника Ефтимова

Резултати

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

Код

def is_pangram(sentence):
"""
Checks if given string contains all characters in bulgarian alphabet.
"""
bulgarian_alphabet = [char_code for char_code in range(ord('а'), ord('я'))
if char_code not in [ord('ы'), ord('э')]]
sentence_chars = [ord(char) for char in sentence.lower()]
return set(sentence_chars).issuperset(set(bulgarian_alphabet))
def char_histogram(text):
"""
Counts the occurence of a character in a given string.
"""
from collections import defaultdict
text_chars = [char for char in text]
char_counter = defaultdict(int)
for group in text_chars:
char_counter[group] += 1
return char_counter
def sort_by(func, arguments):
"""
Sorts list by a given function.
"""
from functools import cmp_to_key
arguments.sort(key=cmp_to_key(func))
return arguments
def group_by_type(dictionary):
"""
Splits a dictionary into dictionaries by the type of the keys of the former
one.
"""
return {
type(group_key): {
key: dictionary[key] for key in
set(filter(lambda x: isinstance(x, type(group_key)), dictionary))
} for group_key in dictionary}
def anagrams(words):
"""
Groups a list of strings by the letters used in the string.
"""
from itertools import groupby
import re
return [
list(group) for key,
group in groupby(
sorted(words, key=len),
lambda x: re.sub('[^A-Za-z0-9]+', '', ''.join(sorted(x))))]

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

.FF.............
======================================================================
FAIL: test_with_different_cases (test.TestAnagrams)
----------------------------------------------------------------------
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-gdb46n/test.py", line 125, in test_with_different_cases
    set(map(frozenset, solution.anagrams(words))))
AssertionError: Items in the first set but not the second:
frozenset({'Ray Adverb', 'Dave Barry'})
Items in the second set but not the first:
frozenset({'Dave Barry'})
frozenset({'Ray Adverb'})

======================================================================
FAIL: test_with_different_symbols (test.TestAnagrams)
----------------------------------------------------------------------
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-gdb46n/test.py", line 135, in test_with_different_symbols
    set(map(frozenset, solution.anagrams(words))))
AssertionError: Items in the first set but not the second:
frozenset({"So I'm cuter", 'Tom Cruise'})
frozenset({'Tom Marvolo Riddle', 'I am Lord Voldemort'})
Items in the second set but not the first:
frozenset({'Tom Cruise'})
frozenset({"So I'm cuter"})
frozenset({'Tom Marvolo Riddle'})
frozenset({'I am Lord Voldemort'})

----------------------------------------------------------------------
Ran 16 tests in 0.011s

FAILED (failures=2)

История (10 версии и 4 коментара)

Моника обнови решението на 12.03.2014 23:56 (преди над 10 години)

+def ascii_breakdown(sentence):
+ """
+ Breaks down a string to a set of ASCII codes of characters.
+ """
+ return set(ord(character) for character in sentence)
+
+def is_pangram(sentence):
+ """
+ Checks if given string contains all characters in cyrillyc(bg) alphabet.
+ """
+ cyrillic_chars = set(range(ord('а'), ord('я'))) - {ord('ы'), ord('э')}
+
+ return ascii_breakdown(sentence.lower()).issuperset(cyrillic)
+

Моника обнови решението на 17.03.2014 05:56 (преди над 10 години)

-def ascii_breakdown(sentence):
+def string_to_ascii(string):
"""
Breaks down a string to a set of ASCII codes of characters.
"""
- return set(ord(character) for character in sentence)
+ return set(ord(character) for character in string)
+
+
def is_pangram(sentence):
"""
- Checks if given string contains all characters in cyrillyc(bg) alphabet.
+ Checks if given string contains all characters in bulgarian alphabet.
"""
- cyrillic_chars = set(range(ord('а'), ord('я'))) - {ord('ы'), ord('э')}
- return ascii_breakdown(sentence.lower()).issuperset(cyrillic)
+ bulgarian_alphabet = set(range(ord('а'), ord('я'))) - {ord('ы'), ord('э')}
+ sentence = sentence.lower()
+ return string_to_ascii(sentence).issuperset(bulgarian_alphabet)
+
+
+def char_histogram(text):
+ """
+ Counts the occurence of a character in string.
+ """
+
+ characters = [character for character in text]
+ character_counter = dict()
+
+ for group in characters:
+ character_counter.setdefault(group, 0)
+ character_counter[group] += 1
+
+ return character_counter
+
+
+def sort_by(func, arguments):
+ """
+
+ """
+
+ return None
+
+
+def group_by_type(dictionary):
+ """
+
+ """
+
+ return None
+
+
+def anagrams(words):
+ """
+
+ """
+
+ return ()

Моника обнови решението на 17.03.2014 09:11 (преди над 10 години)

def string_to_ascii(string):
"""
Breaks down a string to a set of ASCII codes of characters.
"""
return set(ord(character) for character in string)
def is_pangram(sentence):
"""
Checks if given string contains all characters in bulgarian alphabet.
"""
bulgarian_alphabet = set(range(ord('а'), ord('я'))) - {ord('ы'), ord('э')}
sentence = sentence.lower()
return string_to_ascii(sentence).issuperset(bulgarian_alphabet)
def char_histogram(text):
"""
Counts the occurence of a character in string.
"""
characters = [character for character in text]
character_counter = dict()
for group in characters:
character_counter.setdefault(group, 0)
character_counter[group] += 1
return character_counter
def sort_by(func, arguments):
"""
"""
return None
def group_by_type(dictionary):
"""
"""
return None
def anagrams(words):
"""
-
+ Groups a list by the same characters used in a string.
"""
+ from itertools import groupby
- return ()
+ return [
+ list(group) for key,
+ group in groupby(
+ sorted(
+ words,
+ key=sorted),
+ sorted)]

Моника обнови решението на 17.03.2014 11:10 (преди над 10 години)

def string_to_ascii(string):
"""
Breaks down a string to a set of ASCII codes of characters.
"""
return set(ord(character) for character in string)
def is_pangram(sentence):
"""
Checks if given string contains all characters in bulgarian alphabet.
"""
bulgarian_alphabet = set(range(ord('а'), ord('я'))) - {ord('ы'), ord('э')}
sentence = sentence.lower()
return string_to_ascii(sentence).issuperset(bulgarian_alphabet)
def char_histogram(text):
"""
Counts the occurence of a character in string.
"""
characters = [character for character in text]
character_counter = dict()
for group in characters:
character_counter.setdefault(group, 0)
character_counter[group] += 1
return character_counter
def sort_by(func, arguments):
"""
"""
return None
def group_by_type(dictionary):
"""
-
+ Splits a dictionary into dictionaries by the type of the keys of the former one.
"""
- return None
+ return {
+ type(group_key): {
+ key: dictionary[key] for key in set(
+ filter(
+ lambda x: isinstance(
+ x,
+ type(group_key)),
+ dictionary))} for group_key in dictionary}
def anagrams(words):
"""
- Groups a list by the same characters used in a string.
+ Groups a list of strings by the characters used in the string.
"""
from itertools import groupby
return [
list(group) for key,
group in groupby(
sorted(
words,
- key=sorted),
+ key=len),
sorted)]

Моника обнови решението на 17.03.2014 11:14 (преди над 10 години)

def string_to_ascii(string):
"""
Breaks down a string to a set of ASCII codes of characters.
"""
return set(ord(character) for character in string)
def is_pangram(sentence):
"""
Checks if given string contains all characters in bulgarian alphabet.
"""
bulgarian_alphabet = set(range(ord('а'), ord('я'))) - {ord('ы'), ord('э')}
sentence = sentence.lower()
return string_to_ascii(sentence).issuperset(bulgarian_alphabet)
def char_histogram(text):
"""
- Counts the occurence of a character in string.
+ Counts the occurence of a character in a given string.
"""
+ from collections import defaultdict
characters = [character for character in text]
- character_counter = dict()
+ character_counter = defaultdict(int)
for group in characters:
- character_counter.setdefault(group, 0)
character_counter[group] += 1
return character_counter
def sort_by(func, arguments):
"""
"""
return None
def group_by_type(dictionary):
"""
Splits a dictionary into dictionaries by the type of the keys of the former one.
"""
return {
type(group_key): {
key: dictionary[key] for key in set(
filter(
lambda x: isinstance(
x,
type(group_key)),
dictionary))} for group_key in dictionary}
def anagrams(words):
"""
Groups a list of strings by the characters used in the string.
"""
from itertools import groupby
return [
list(group) for key,
group in groupby(
sorted(
words,
key=len),
sorted)]

Моника обнови решението на 18.03.2014 07:30 (преди над 10 години)

-def string_to_ascii(string):
- """
- Breaks down a string to a set of ASCII codes of characters.
- """
-
- return set(ord(character) for character in string)
-
-
def is_pangram(sentence):
"""
Checks if given string contains all characters in bulgarian alphabet.
"""
- bulgarian_alphabet = set(range(ord('а'), ord('я'))) - {ord('ы'), ord('э')}
- sentence = sentence.lower()
+ bulgarian_alphabet = [code for code in range(ord('а'), ord('я'))
+ if code not in [ord('ы'), ord('э')]]
- return string_to_ascii(sentence).issuperset(bulgarian_alphabet)
+ sentence_characters = [ord(character) for character in sentence.lower()]
+ return set(sentence_characters).issuperset(set(bulgarian_alphabet))
+
def char_histogram(text):
"""
Counts the occurence of a character in a given string.
"""
from collections import defaultdict
- characters = [character for character in text]
+ text_characters = [character for character in text]
character_counter = defaultdict(int)
- for group in characters:
+ for group in text_characters:
character_counter[group] += 1
return character_counter
def sort_by(func, arguments):
"""
-
+ Sorts list by a given function.
"""
+ from functools import cmp_to_key
- return None
+ arguments.sort(key=cmp_to_key(func))
+ return arguments
+
def group_by_type(dictionary):
"""
- Splits a dictionary into dictionaries by the type of the keys of the former one.
+ Splits a dictionary into dictionaries by the type of the keys of the former
+ one.
"""
return {
type(group_key): {
- key: dictionary[key] for key in set(
- filter(
- lambda x: isinstance(
- x,
- type(group_key)),
- dictionary))} for group_key in dictionary}
+ key: dictionary[key] for key in
+ set(filter(lambda x: isinstance(x, type(group_key)), dictionary))
+ } for group_key in dictionary}
def anagrams(words):
"""
Groups a list of strings by the characters used in the string.
"""
from itertools import groupby
- return [
- list(group) for key,
+ return [list(group) for key, group in groupby(
- group in groupby(
+ sorted(words, key=len), sorted)]
- sorted(
- words,
- key=len),
- sorted)]

Моника обнови решението на 18.03.2014 07:31 (преди над 10 години)

def is_pangram(sentence):
"""
Checks if given string contains all characters in bulgarian alphabet.
"""
bulgarian_alphabet = [code for code in range(ord('а'), ord('я'))
if code not in [ord('ы'), ord('э')]]
sentence_characters = [ord(character) for character in sentence.lower()]
return set(sentence_characters).issuperset(set(bulgarian_alphabet))
def char_histogram(text):
"""
Counts the occurence of a character in a given string.
"""
from collections import defaultdict
text_characters = [character for character in text]
character_counter = defaultdict(int)
for group in text_characters:
character_counter[group] += 1
return character_counter
def sort_by(func, arguments):
"""
Sorts list by a given function.
"""
from functools import cmp_to_key
arguments.sort(key=cmp_to_key(func))
return arguments
def group_by_type(dictionary):
"""
Splits a dictionary into dictionaries by the type of the keys of the former
one.
"""
return {
type(group_key): {
key: dictionary[key] for key in
set(filter(lambda x: isinstance(x, type(group_key)), dictionary))
} for group_key in dictionary}
def anagrams(words):
"""
Groups a list of strings by the characters used in the string.
"""
from itertools import groupby
return [list(group) for key, group in groupby(
sorted(words, key=len), sorted)]
+

Моника обнови решението на 19.03.2014 08:43 (преди над 10 години)

def is_pangram(sentence):
"""
Checks if given string contains all characters in bulgarian alphabet.
"""
- bulgarian_alphabet = [code for code in range(ord('а'), ord('я'))
- if code not in [ord('ы'), ord('э')]]
+ bulgarian_alphabet = [char_code for char_code in range(ord('а'), ord('я'))
+ if char_code not in [ord('ы'), ord('э')]]
- sentence_characters = [ord(character) for character in sentence.lower()]
+ sentence_chars = [ord(char) for char in sentence.lower()]
- return set(sentence_characters).issuperset(set(bulgarian_alphabet))
+ return set(sentence_chars).issuperset(set(bulgarian_alphabet))
def char_histogram(text):
"""
Counts the occurence of a character in a given string.
"""
from collections import defaultdict
- text_characters = [character for character in text]
- character_counter = defaultdict(int)
+ text_chars = [char for char in text]
+ char_counter = defaultdict(int)
- for group in text_characters:
- character_counter[group] += 1
+ for group in text_chars:
+ char_counter[group] += 1
- return character_counter
+ return char_counter
def sort_by(func, arguments):
"""
Sorts list by a given function.
"""
from functools import cmp_to_key
arguments.sort(key=cmp_to_key(func))
return arguments
def group_by_type(dictionary):
"""
Splits a dictionary into dictionaries by the type of the keys of the former
one.
"""
return {
type(group_key): {
key: dictionary[key] for key in
set(filter(lambda x: isinstance(x, type(group_key)), dictionary))
} for group_key in dictionary}
def anagrams(words):
"""
Groups a list of strings by the characters used in the string.
"""
from itertools import groupby
+ import re
- return [list(group) for key, group in groupby(
- sorted(words, key=len), sorted)]
+ return [
-
+ list(group) for key,
+ group in groupby(
+ sorted(words, key=len),
+ lambda x: re.sub('[^A-Za-z0-9]+', '', ''.join(sorted(x))))]

Моника обнови решението на 19.03.2014 08:53 (преди над 10 години)

def is_pangram(sentence):
"""
Checks if given string contains all characters in bulgarian alphabet.
"""
bulgarian_alphabet = [char_code for char_code in range(ord('а'), ord('я'))
if char_code not in [ord('ы'), ord('э')]]
sentence_chars = [ord(char) for char in sentence.lower()]
return set(sentence_chars).issuperset(set(bulgarian_alphabet))
def char_histogram(text):
"""
Counts the occurence of a character in a given string.
"""
from collections import defaultdict
text_chars = [char for char in text]
char_counter = defaultdict(int)
for group in text_chars:
char_counter[group] += 1
return char_counter
def sort_by(func, arguments):
"""
Sorts list by a given function.
"""
from functools import cmp_to_key
arguments.sort(key=cmp_to_key(func))
return arguments
def group_by_type(dictionary):
"""
Splits a dictionary into dictionaries by the type of the keys of the former
one.
"""
return {
type(group_key): {
key: dictionary[key] for key in
set(filter(lambda x: isinstance(x, type(group_key)), dictionary))
} for group_key in dictionary}
def anagrams(words):
"""
Groups a list of strings by the characters used in the string.
"""
from itertools import groupby
import re
return [
list(group) for key,
group in groupby(
sorted(words, key=len),
lambda x: re.sub('[^A-Za-z0-9]+', '', ''.join(sorted(x))))]
+

Моника обнови решението на 19.03.2014 09:04 (преди над 10 години)

def is_pangram(sentence):
"""
Checks if given string contains all characters in bulgarian alphabet.
"""
bulgarian_alphabet = [char_code for char_code in range(ord('а'), ord('я'))
if char_code not in [ord('ы'), ord('э')]]
sentence_chars = [ord(char) for char in sentence.lower()]
return set(sentence_chars).issuperset(set(bulgarian_alphabet))
def char_histogram(text):
"""
Counts the occurence of a character in a given string.
"""
from collections import defaultdict
text_chars = [char for char in text]
char_counter = defaultdict(int)
for group in text_chars:
char_counter[group] += 1
return char_counter
def sort_by(func, arguments):
"""
Sorts list by a given function.
"""
from functools import cmp_to_key
arguments.sort(key=cmp_to_key(func))
return arguments
def group_by_type(dictionary):
"""
Splits a dictionary into dictionaries by the type of the keys of the former
one.
"""
return {
type(group_key): {
key: dictionary[key] for key in
set(filter(lambda x: isinstance(x, type(group_key)), dictionary))
} for group_key in dictionary}
def anagrams(words):
"""
- Groups a list of strings by the characters used in the string.
+ Groups a list of strings by the letters used in the string.
"""
from itertools import groupby
import re
return [
list(group) for key,
group in groupby(
sorted(words, key=len),
lambda x: re.sub('[^A-Za-z0-9]+', '', ''.join(sorted(x))))]