Решение на Пет функции от Антонио Николов

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

Към профила на Антонио Николов

Резултати

  • 10 точки от тестове
  • 0 бонус точки
  • 10 точки общо
  • 16 успешни тест(а)
  • 0 неуспешни тест(а)

Код

import functools
import string
from collections import defaultdict
def is_pangram(sentence):
all_chars = {'ы', 'э'}
for char in sentence.lower():
if ord(char) in range(ord('а'), ord('я') + 1):
all_chars.add(char)
return len(all_chars) == 32
def char_histogram(text):
count_char = {}
for char in text:
if not count_char.get(char):
count_char[char] = text.count(char)
return count_char
def sort_by(func, arguments):
return sorted(arguments, key=functools.cmp_to_key(func))
def group_by_type(dictionary):
grouped = defaultdict(dict)
for key, value in dictionary.items():
items_till_now = list(grouped[type(key)].items())
grouped[type(key)] = dict(items_till_now + list({key: value}.items()))
return dict(grouped)
def letters(word):
ignored = string.punctuation + string.whitespace + '–'
return sorted(list(filter(lambda x: x not in ignored, word.lower())))
def anagrams(words):
grouped = []
for faith in words:
subgroup = list(filter(lambda x: letters(x) == letters(faith), words))
if subgroup not in grouped:
grouped.append(subgroup)
return grouped

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

................
----------------------------------------------------------------------
Ran 16 tests in 0.016s

OK

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

Антонио обнови решението на 14.03.2014 01:33 (преди над 10 години)

+import functools
+
+from collections import defaultdict
+
+
+def is_pangram(sentence):
+ all_chars = {'ы', 'э'}
+
+ for char in sentence.lower():
+ if ord(char) in range(ord('а'), ord('я') + 1):
+ all_chars.add(char)
+
+ return len(all_chars) == 32
+
+
+def char_histogram(text):
+ count_char = {}
+
+ for char in text:
+ if not count_char.get(char):
+ count_char[char] = text.count(char)
+
+ return count_char
+
+
+def sort_by(func, arguments):
+ return sorted(arguments, key=functools.cmp_to_key(func))
+
+
+def group_by_type(dictionary):
+ grouped = defaultdict(lambda: {})
+
+ for key, value in dictionary.items():
+ items_till_now = list(grouped[type(key)].items())
+ grouped[type(key)] = dict(items_till_now + list({key: value}.items()))
+
+ return dict(grouped)
+
+
+def anagrams(words):
+ grouped = []
+
+ for vocable in words:
+ new = list(filter(lambda x: sorted(list(x)) == sorted(list(vocable)),
+ words))
+ if not new in grouped:
+ grouped.append(new)
+
+ return grouped

Антонио обнови решението на 17.03.2014 13:27 (преди над 10 години)

import functools
-
+import string
from collections import defaultdict
def is_pangram(sentence):
all_chars = {'ы', 'э'}
for char in sentence.lower():
if ord(char) in range(ord('а'), ord('я') + 1):
all_chars.add(char)
return len(all_chars) == 32
def char_histogram(text):
count_char = {}
for char in text:
if not count_char.get(char):
count_char[char] = text.count(char)
return count_char
def sort_by(func, arguments):
return sorted(arguments, key=functools.cmp_to_key(func))
def group_by_type(dictionary):
grouped = defaultdict(lambda: {})
for key, value in dictionary.items():
items_till_now = list(grouped[type(key)].items())
grouped[type(key)] = dict(items_till_now + list({key: value}.items()))
return dict(grouped)
+def letters(word):
+ ignored = string.punctuation + string.whitespace
+
+ return sorted(list(filter(lambda x: x not in ignored, word.lower())))
+
+
def anagrams(words):
grouped = []
for vocable in words:
- new = list(filter(lambda x: sorted(list(x)) == sorted(list(vocable)),
- words))
- if not new in grouped:
- grouped.append(new)
+ subgroup = filter(lambda x: letters(x) == letters(vocable), words)
- return grouped
+ if subgroup not in grouped:
+ grouped.append(list(subgroup))
+
+ return grouped

Антонио обнови решението на 17.03.2014 23:07 (преди над 10 години)

import functools
import string
from collections import defaultdict
def is_pangram(sentence):
all_chars = {'ы', 'э'}
for char in sentence.lower():
if ord(char) in range(ord('а'), ord('я') + 1):
all_chars.add(char)
return len(all_chars) == 32
def char_histogram(text):
count_char = {}
for char in text:
if not count_char.get(char):
count_char[char] = text.count(char)
return count_char
def sort_by(func, arguments):
return sorted(arguments, key=functools.cmp_to_key(func))
def group_by_type(dictionary):
grouped = defaultdict(lambda: {})
for key, value in dictionary.items():
items_till_now = list(grouped[type(key)].items())
grouped[type(key)] = dict(items_till_now + list({key: value}.items()))
return dict(grouped)
def letters(word):
ignored = string.punctuation + string.whitespace
return sorted(list(filter(lambda x: x not in ignored, word.lower())))
def anagrams(words):
grouped = []
- for vocable in words:
- subgroup = filter(lambda x: letters(x) == letters(vocable), words)
+ for faith in words:
+ subgroup = list(filter(lambda x: letters(x) == letters(faith), words))
if subgroup not in grouped:
- grouped.append(list(subgroup))
+ grouped.append(subgroup)
return grouped

Антонио обнови решението на 18.03.2014 19:07 (преди над 10 години)

import functools
import string
from collections import defaultdict
def is_pangram(sentence):
all_chars = {'ы', 'э'}
for char in sentence.lower():
if ord(char) in range(ord('а'), ord('я') + 1):
all_chars.add(char)
return len(all_chars) == 32
def char_histogram(text):
count_char = {}
for char in text:
if not count_char.get(char):
count_char[char] = text.count(char)
return count_char
def sort_by(func, arguments):
return sorted(arguments, key=functools.cmp_to_key(func))
def group_by_type(dictionary):
- grouped = defaultdict(lambda: {})
+ grouped = defaultdict(dict)
for key, value in dictionary.items():
items_till_now = list(grouped[type(key)].items())
grouped[type(key)] = dict(items_till_now + list({key: value}.items()))
return dict(grouped)
def letters(word):
ignored = string.punctuation + string.whitespace
return sorted(list(filter(lambda x: x not in ignored, word.lower())))
def anagrams(words):
grouped = []
for faith in words:
subgroup = list(filter(lambda x: letters(x) == letters(faith), words))
if subgroup not in grouped:
grouped.append(subgroup)
return grouped

Антонио обнови решението на 19.03.2014 01:20 (преди над 10 години)

import functools
import string
from collections import defaultdict
def is_pangram(sentence):
all_chars = {'ы', 'э'}
for char in sentence.lower():
if ord(char) in range(ord('а'), ord('я') + 1):
all_chars.add(char)
return len(all_chars) == 32
def char_histogram(text):
count_char = {}
for char in text:
if not count_char.get(char):
count_char[char] = text.count(char)
return count_char
def sort_by(func, arguments):
return sorted(arguments, key=functools.cmp_to_key(func))
def group_by_type(dictionary):
grouped = defaultdict(dict)
for key, value in dictionary.items():
items_till_now = list(grouped[type(key)].items())
grouped[type(key)] = dict(items_till_now + list({key: value}.items()))
return dict(grouped)
def letters(word):
- ignored = string.punctuation + string.whitespace
+ ignored = string.punctuation + string.whitespace + '–'
return sorted(list(filter(lambda x: x not in ignored, word.lower())))
def anagrams(words):
grouped = []
for faith in words:
subgroup = list(filter(lambda x: letters(x) == letters(faith), words))
if subgroup not in grouped:
grouped.append(subgroup)
return grouped