Решение на Пет функции от Стоян Цветков

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

Към профила на Стоян Цветков

Резултати

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

Код

import string
import functools
PARASITES = {'Э', 'э', 'Ы', 'ы'}
def is_pangram(sentence):
bg_alpha = {chr(code) for code in range(ord('А'), ord('я') + 1)}
input_letters = {letter for letter in sentence.upper()}
return len(bg_alpha - PARASITES - input_letters) == 30
def char_histogram(text):
return {symbol: text.count(symbol) for symbol in text}
def group_by_type(dictionary):
keys = dictionary.keys()
same = lambda x, y: type(x) == type(y)
return {type(k1): {k2: dictionary[k2] for k2 in keys if same(k1, k2)} for k1 in keys}
def strip(dictionary, acceptable_chars):
chars_to_ignore = []
for key in dictionary.keys():
if key not in acceptable_chars:
chars_to_ignore.append(key)
for element in chars_to_ignore:
del(dictionary[element])
return dictionary
#f**k this shitty function
def anagrams(words):
copy = [word.lower() for word in words]
alpha = string.ascii_lowercase
anagram = lambda x, y: strip(char_histogram(x), alpha) == strip(char_histogram(y), alpha)
result = list({tuple([y for y in copy if anagram(x, y)]) for x in copy})
result = list(map(list, result))
for word in words:
for x in range(len(result)):
for y in range(len(result[x])):
if result[x][y] == word.lower():
result[x][y] = word
return result
def sort_by(func, arguments):
return sorted(arguments, key=functools.cmp_to_key(func))

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

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

OK

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

Стоян обнови решението на 14.03.2014 00:44 (преди над 10 години)

+PARASITES = {'Э', 'э', 'Ы', 'ы'}
+def is_pangram(sentence):
+ bg_alpha = {chr(code) for code in range(ord('А'), ord('я') + 1)}
+ inp = {letter for letter in sentence.upper()}
+ return len(bg_alpha - PARASITES - inp) == 30
+
+def char_histogram(text):
+ return {symbol: text.count(symbol) for symbol in text}
+
+def group_by_type(dictionary):
+ keys = dictionary.keys()
+ same = lambda x, y: type(x) == type(y)
+ return {type(k1): {k2: dictionary[k2] for k2 in keys if same(k1, k2)} for k1 in keys}
+
+def anagrams(words):
+ anagram = lambda x, y: char_histogram(x) == char_histogram(y)
+ return list({tuple([y for y in words if anagram(x, y)]) for x in words})
+
+import functools
+def sort_by(func, arguments):
+ return sorted(arguments, key=functools.cmp_to_key(func))

Стоян обнови решението на 14.03.2014 13:40 (преди над 10 години)

+import functools
PARASITES = {'Э', 'э', 'Ы', 'ы'}
+
def is_pangram(sentence):
bg_alpha = {chr(code) for code in range(ord('А'), ord('я') + 1)}
- inp = {letter for letter in sentence.upper()}
- return len(bg_alpha - PARASITES - inp) == 30
+ input_letters = {letter for letter in sentence.upper()}
+ return len(bg_alpha - PARASITES - input_letters) == 30
def char_histogram(text):
return {symbol: text.count(symbol) for symbol in text}
def group_by_type(dictionary):
keys = dictionary.keys()
same = lambda x, y: type(x) == type(y)
return {type(k1): {k2: dictionary[k2] for k2 in keys if same(k1, k2)} for k1 in keys}
def anagrams(words):
anagram = lambda x, y: char_histogram(x) == char_histogram(y)
return list({tuple([y for y in words if anagram(x, y)]) for x in words})
-import functools
def sort_by(func, arguments):
return sorted(arguments, key=functools.cmp_to_key(func))

Стоян обнови решението на 17.03.2014 01:08 (преди над 10 години)

+import string
import functools
PARASITES = {'Э', 'э', 'Ы', 'ы'}
-
def is_pangram(sentence):
bg_alpha = {chr(code) for code in range(ord('А'), ord('я') + 1)}
input_letters = {letter for letter in sentence.upper()}
return len(bg_alpha - PARASITES - input_letters) == 30
def char_histogram(text):
return {symbol: text.count(symbol) for symbol in text}
def group_by_type(dictionary):
keys = dictionary.keys()
same = lambda x, y: type(x) == type(y)
return {type(k1): {k2: dictionary[k2] for k2 in keys if same(k1, k2)} for k1 in keys}
+def strip(dictionary, acceptable):
+ to_del = []
+ for key in dictionary.keys():
+ if key not in acceptable:
+ to_del.append(key)
+ for element in to_del:
+ del(dictionary[element])
+ return dictionary
+
+#f**k this shitty function
def anagrams(words):
- anagram = lambda x, y: char_histogram(x) == char_histogram(y)
- return list({tuple([y for y in words if anagram(x, y)]) for x in words})
+ copy = [word.lower() for word in words]
+ alpha = string.ascii_lowercase
+ anagram = lambda x, y: strip(char_histogram(x), alpha) == strip(char_histogram(y), alpha)
+ result = list({tuple([y for y in copy if anagram(x, y)]) for x in copy})
+ result = list(map(list, result))
+ for word in words:
+ for x in range(len(result)):
+ for y in range(len(result[x])):
+ if result[x][y] == word.lower():
+ result[x][y] = word
+ return result
def sort_by(func, arguments):
return sorted(arguments, key=functools.cmp_to_key(func))

Стоян обнови решението на 19.03.2014 11:36 (преди над 10 години)

import string
import functools
PARASITES = {'Э', 'э', 'Ы', 'ы'}
def is_pangram(sentence):
bg_alpha = {chr(code) for code in range(ord('А'), ord('я') + 1)}
input_letters = {letter for letter in sentence.upper()}
return len(bg_alpha - PARASITES - input_letters) == 30
+
def char_histogram(text):
return {symbol: text.count(symbol) for symbol in text}
+
def group_by_type(dictionary):
keys = dictionary.keys()
same = lambda x, y: type(x) == type(y)
return {type(k1): {k2: dictionary[k2] for k2 in keys if same(k1, k2)} for k1 in keys}
-def strip(dictionary, acceptable):
- to_del = []
+
+def strip(dictionary, acceptable_chars):
+ chars_to_ignore = []
for key in dictionary.keys():
- if key not in acceptable:
- to_del.append(key)
- for element in to_del:
+ if key not in acceptable_chars:
+ chars_to_ignore.append(key)
+ for element in chars_to_ignore:
del(dictionary[element])
return dictionary
+
#f**k this shitty function
def anagrams(words):
copy = [word.lower() for word in words]
alpha = string.ascii_lowercase
anagram = lambda x, y: strip(char_histogram(x), alpha) == strip(char_histogram(y), alpha)
result = list({tuple([y for y in copy if anagram(x, y)]) for x in copy})
result = list(map(list, result))
for word in words:
for x in range(len(result)):
for y in range(len(result[x])):
if result[x][y] == word.lower():
result[x][y] = word
return result
+
def sort_by(func, arguments):
return sorted(arguments, key=functools.cmp_to_key(func))