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

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

Към профила на Ралица Цанова

Резултати

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

Код

from functools import cmp_to_key
from collections import defaultdict
from collections import Counter
import re
CYRILLIC = set('абвгдежзийклмнопрстуфхцчшщьъюя')
def is_pangram(sentence):
return CYRILLIC - set(sentence.lower()) == set()
def char_histogram(text):
item_repetitions = {}
for symbol in text:
if symbol not in item_repetitions.keys():
item_repetitions[symbol] = 0
item_repetitions[symbol] += 1
return item_repetitions
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(dictionary):
result = defaultdict(dict)
for key, value in dictionary.items():
(result[(type(key))])[key] = value
return dict(result)
def change(string):
return re.sub(r'[\W_\d]+', '', string).lower()
def anagrams(words):
if words == []:
return words
word = change(words[0])
result = [x for x in words if not Counter(change(x)) == Counter(word)]
return [[x for x in words if not x in result]] + anagrams(result)

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

................
----------------------------------------------------------------------
Ran 16 tests in 0.012s

OK

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

Ралица обнови решението на 15.03.2014 15:03 (преди над 10 години)

+from functools import cmp_to_key
+from collections import defaultdict
+CYRILLIC = set('абвгдежзийклмнопрстуфхцчшщьъюя')
+
+
+def is_pangram(sentence):
+ return CYRILLIC - set(sentence.lower()) == set()
+
+
+def char_histogram(text):
+ item_repetitions = {}
+ for symbol in text:
+ if symbol not in item_repetitions.keys():
+ item_repetitions[symbol] = 0
+ item_repetitions[symbol] += 1
+ return item_repetitions
+
+
+def sort_by(func, arguments):
+ return sorted(arguments, key=cmp_to_key(func))
+
+
+def group_by_type(dictionary):
+ v = defaultdict(dict)
+ for key, value in dictionary.items():
+ (v[(type(key))])[key] = value
+ return dict(v)
+
+
+def anagrams(words):
+ if words == []:
+ return words
+ left = [x for x in words if not set(x) == set(words[0])]
+ return [[x for x in words if set(x) == set(words[0])]] + anagrams(left)

Ралица обнови решението на 15.03.2014 18:48 (преди над 10 години)

from functools import cmp_to_key
from collections import defaultdict
+import re
CYRILLIC = set('абвгдежзийклмнопрстуфхцчшщьъюя')
def is_pangram(sentence):
return CYRILLIC - set(sentence.lower()) == set()
def char_histogram(text):
item_repetitions = {}
for symbol in text:
if symbol not in item_repetitions.keys():
item_repetitions[symbol] = 0
item_repetitions[symbol] += 1
return item_repetitions
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(dictionary):
- v = defaultdict(dict)
+ result = defaultdict(dict)
for key, value in dictionary.items():
- (v[(type(key))])[key] = value
- return dict(v)
+ (result[(type(key))])[key] = value
+ return dict(result)
+def convert(string):
+ return re.sub(r'[^a-zA-z]', '', string)
+
+
def anagrams(words):
if words == []:
return words
- left = [x for x in words if not set(x) == set(words[0])]
- return [[x for x in words if set(x) == set(words[0])]] + anagrams(left)
+ left = [x for x in words if not set(convert(x)) == set(convert(words[0]))]
+ return [list(set(words) - set(left))] + anagrams(left)

Ами мисля,че в случая точно това правя,тоест ако имам 'the ..323eyes', 'the2112y-see' - те са анаграми,тъй като остават буквите 'theeyes' и 'theysee'.Пробвах с всякакви такива примерчета и работеше или имате в предвид,че съм изпуснала някой страничен случай?

Ралица обнови решението на 16.03.2014 00:31 (преди над 10 години)

from functools import cmp_to_key
from collections import defaultdict
import re
CYRILLIC = set('абвгдежзийклмнопрстуфхцчшщьъюя')
def is_pangram(sentence):
return CYRILLIC - set(sentence.lower()) == set()
def char_histogram(text):
item_repetitions = {}
for symbol in text:
if symbol not in item_repetitions.keys():
item_repetitions[symbol] = 0
item_repetitions[symbol] += 1
return item_repetitions
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(dictionary):
result = defaultdict(dict)
for key, value in dictionary.items():
(result[(type(key))])[key] = value
return dict(result)
def convert(string):
- return re.sub(r'[^a-zA-z]', '', string)
+ return re.sub(r'[^a-zA-Z]', '', string).lower()
def anagrams(words):
if words == []:
return words
left = [x for x in words if not set(convert(x)) == set(convert(words[0]))]
return [list(set(words) - set(left))] + anagrams(left)

Ралица обнови решението на 16.03.2014 00:34 (преди над 10 години)

from functools import cmp_to_key
from collections import defaultdict
import re
CYRILLIC = set('абвгдежзийклмнопрстуфхцчшщьъюя')
def is_pangram(sentence):
return CYRILLIC - set(sentence.lower()) == set()
def char_histogram(text):
item_repetitions = {}
for symbol in text:
if symbol not in item_repetitions.keys():
item_repetitions[symbol] = 0
item_repetitions[symbol] += 1
return item_repetitions
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(dictionary):
result = defaultdict(dict)
for key, value in dictionary.items():
(result[(type(key))])[key] = value
return dict(result)
def convert(string):
- return re.sub(r'[^a-zA-Z]', '', string).lower()
+ return re.sub(r'[^a-zA-Z]', '', string)
def anagrams(words):
if words == []:
return words
left = [x for x in words if not set(convert(x)) == set(convert(words[0]))]
return [list(set(words) - set(left))] + anagrams(left)

Ралица обнови решението на 16.03.2014 00:45 (преди над 10 години)

from functools import cmp_to_key
from collections import defaultdict
import re
CYRILLIC = set('абвгдежзийклмнопрстуфхцчшщьъюя')
def is_pangram(sentence):
return CYRILLIC - set(sentence.lower()) == set()
def char_histogram(text):
item_repetitions = {}
for symbol in text:
if symbol not in item_repetitions.keys():
item_repetitions[symbol] = 0
item_repetitions[symbol] += 1
return item_repetitions
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(dictionary):
result = defaultdict(dict)
for key, value in dictionary.items():
(result[(type(key))])[key] = value
return dict(result)
def convert(string):
- return re.sub(r'[^a-zA-Z]', '', string)
+ return re.sub(r'[^a-zA-Z]', '', string).lower()
def anagrams(words):
if words == []:
return words
left = [x for x in words if not set(convert(x)) == set(convert(words[0]))]
return [list(set(words) - set(left))] + anagrams(left)

Ралица обнови решението на 16.03.2014 22:52 (преди над 10 години)

from functools import cmp_to_key
from collections import defaultdict
import re
CYRILLIC = set('абвгдежзийклмнопрстуфхцчшщьъюя')
def is_pangram(sentence):
return CYRILLIC - set(sentence.lower()) == set()
def char_histogram(text):
item_repetitions = {}
for symbol in text:
if symbol not in item_repetitions.keys():
item_repetitions[symbol] = 0
item_repetitions[symbol] += 1
return item_repetitions
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(dictionary):
result = defaultdict(dict)
for key, value in dictionary.items():
(result[(type(key))])[key] = value
return dict(result)
-def convert(string):
+def change(string):
return re.sub(r'[^a-zA-Z]', '', string).lower()
def anagrams(words):
if words == []:
return words
- left = [x for x in words if not set(convert(x)) == set(convert(words[0]))]
- return [list(set(words) - set(left))] + anagrams(left)
+ result = [x for x in words if not set(change(x)) == set(change(words[0]))]
+ return [list(set(words) - set(result))] + anagrams(result)

Ралица обнови решението на 17.03.2014 00:40 (преди над 10 години)

from functools import cmp_to_key
from collections import defaultdict
import re
+
CYRILLIC = set('абвгдежзийклмнопрстуфхцчшщьъюя')
def is_pangram(sentence):
return CYRILLIC - set(sentence.lower()) == set()
def char_histogram(text):
item_repetitions = {}
for symbol in text:
if symbol not in item_repetitions.keys():
item_repetitions[symbol] = 0
item_repetitions[symbol] += 1
return item_repetitions
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(dictionary):
result = defaultdict(dict)
for key, value in dictionary.items():
(result[(type(key))])[key] = value
return dict(result)
def change(string):
- return re.sub(r'[^a-zA-Z]', '', string).lower()
+ return re.sub(r'[\W_\d]+', '', string).lower()
def anagrams(words):
if words == []:
return words
result = [x for x in words if not set(change(x)) == set(change(words[0]))]
- return [list(set(words) - set(result))] + anagrams(result)
+ return [[x for x in words if not x in result]] + anagrams(result)

Ралица обнови решението на 17.03.2014 02:14 (преди над 10 години)

from functools import cmp_to_key
from collections import defaultdict
+from collections import Counter
import re
CYRILLIC = set('абвгдежзийклмнопрстуфхцчшщьъюя')
def is_pangram(sentence):
return CYRILLIC - set(sentence.lower()) == set()
def char_histogram(text):
item_repetitions = {}
for symbol in text:
if symbol not in item_repetitions.keys():
item_repetitions[symbol] = 0
item_repetitions[symbol] += 1
return item_repetitions
def sort_by(func, arguments):
return sorted(arguments, key=cmp_to_key(func))
def group_by_type(dictionary):
result = defaultdict(dict)
for key, value in dictionary.items():
(result[(type(key))])[key] = value
return dict(result)
def change(string):
return re.sub(r'[\W_\d]+', '', string).lower()
def anagrams(words):
if words == []:
return words
- result = [x for x in words if not set(change(x)) == set(change(words[0]))]
+ word = change(words[0])
+ result = [x for x in words if not Counter(change(x)) == Counter(word)]
return [[x for x in words if not x in result]] + anagrams(result)