Решение на Пет функции от Снежана Спасова

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

Към профила на Снежана Спасова

Резултати

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

Код

import collections
ALPHABET = 'абвгдежзийклмнопрстуфхцчшщьюяъ'
def is_pangram(phrase):
return len(set([x for x in list(phrase.lower()) if x in ALPHABET])) == 30
def char_histogram(sentence):
return collections.Counter(list(sentence))
def sort_by(function, arguments):
for i in range(len(arguments)-1):
for i in range(len(arguments)-1):
if function(arguments[i], arguments[i+1]) > 0:
arguments[i], arguments[i+1] = arguments[i+1], arguments[i]
return arguments
def group_by_type(dictionary):
grouped_items = collections.defaultdict(dict)
for key, value in dictionary.items():
grouped_items[type(key)][key] = value
return grouped_items
def anagrams(words):
anagrams = collections.defaultdict(list)
for word in words:
without_signs = filter(lambda x: x.isalpha(), word.lower())
anagrams[tuple(sorted(without_signs))].append(word)
return list(anagrams.values())

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

................
----------------------------------------------------------------------
Ran 16 tests in 0.009s

OK

История (15 версии и 1 коментар)

Снежана обнови решението на 15.03.2014 10:31 (преди над 10 години)

+import collections
+from collections import defaultdict
+ALPHABET = 'абвгдежзийклмнопрстуфхцчшщьюяъ'
+
+def is_pangram(string):
+ return len(set([x for x in list(string.lower()) if x in ALPHABET])) == 30
+
+def char_histogram(string):
+ return dict(collections.Counter(list(string)))
+
+def sort_by(func, arguments):
+ for i in range(len(arguments)-1):
+ for i in range(len(arguments)-1):
+ if func(arguments[i], arguments[i+1]) > 0:
+ arguments[i], arguments[i+1] = arguments[i+1], arguments[i]
+ return arguments
+
+def group_by_type(dictionary):
+ grouped_items = collections.defaultdict(lambda: dict())
+ for key, value in dictionary.items():
+ grouped_items[type(key)][key] = value
+ return dict(grouped_items)
+
+def anagrams(words):
+ anagrams = defaultdict(list)
+ for word in words:
+ anagrams[tuple(sorted(word))].append(word)
+ return list(anagrams.values())

Снежана обнови решението на 15.03.2014 10:53 (преди над 10 години)

import collections
-from collections import defaultdict
+
ALPHABET = 'абвгдежзийклмнопрстуфхцчшщьюяъ'
def is_pangram(string):
return len(set([x for x in list(string.lower()) if x in ALPHABET])) == 30
def char_histogram(string):
return dict(collections.Counter(list(string)))
def sort_by(func, arguments):
for i in range(len(arguments)-1):
for i in range(len(arguments)-1):
if func(arguments[i], arguments[i+1]) > 0:
arguments[i], arguments[i+1] = arguments[i+1], arguments[i]
return arguments
def group_by_type(dictionary):
grouped_items = collections.defaultdict(lambda: dict())
for key, value in dictionary.items():
grouped_items[type(key)][key] = value
return dict(grouped_items)
def anagrams(words):
- anagrams = defaultdict(list)
+ anagrams = collections.defaultdict(list)
for word in words:
anagrams[tuple(sorted(word))].append(word)
return list(anagrams.values())

Снежана обнови решението на 15.03.2014 10:53 (преди над 10 години)

import collections
-
ALPHABET = 'абвгдежзийклмнопрстуфхцчшщьюяъ'
def is_pangram(string):
return len(set([x for x in list(string.lower()) if x in ALPHABET])) == 30
def char_histogram(string):
return dict(collections.Counter(list(string)))
def sort_by(func, arguments):
for i in range(len(arguments)-1):
for i in range(len(arguments)-1):
if func(arguments[i], arguments[i+1]) > 0:
arguments[i], arguments[i+1] = arguments[i+1], arguments[i]
return arguments
def group_by_type(dictionary):
grouped_items = collections.defaultdict(lambda: dict())
for key, value in dictionary.items():
grouped_items[type(key)][key] = value
return dict(grouped_items)
def anagrams(words):
anagrams = collections.defaultdict(list)
for word in words:
anagrams[tuple(sorted(word))].append(word)
return list(anagrams.values())

Снежана обнови решението на 15.03.2014 13:26 (преди над 10 години)

import collections
ALPHABET = 'абвгдежзийклмнопрстуфхцчшщьюяъ'
def is_pangram(string):
return len(set([x for x in list(string.lower()) if x in ALPHABET])) == 30
def char_histogram(string):
return dict(collections.Counter(list(string)))
def sort_by(func, arguments):
for i in range(len(arguments)-1):
for i in range(len(arguments)-1):
if func(arguments[i], arguments[i+1]) > 0:
arguments[i], arguments[i+1] = arguments[i+1], arguments[i]
return arguments
def group_by_type(dictionary):
grouped_items = collections.defaultdict(lambda: dict())
for key, value in dictionary.items():
grouped_items[type(key)][key] = value
return dict(grouped_items)
def anagrams(words):
anagrams = collections.defaultdict(list)
for word in words:
- anagrams[tuple(sorted(word))].append(word)
+ anagrams[tuple(sorted(word.lower()))].append(word)
return list(anagrams.values())

Снежана обнови решението на 15.03.2014 17:35 (преди над 10 години)

import collections
ALPHABET = 'абвгдежзийклмнопрстуфхцчшщьюяъ'
def is_pangram(string):
return len(set([x for x in list(string.lower()) if x in ALPHABET])) == 30
def char_histogram(string):
return dict(collections.Counter(list(string)))
def sort_by(func, arguments):
for i in range(len(arguments)-1):
for i in range(len(arguments)-1):
if func(arguments[i], arguments[i+1]) > 0:
arguments[i], arguments[i+1] = arguments[i+1], arguments[i]
return arguments
def group_by_type(dictionary):
grouped_items = collections.defaultdict(lambda: dict())
for key, value in dictionary.items():
grouped_items[type(key)][key] = value
return dict(grouped_items)
def anagrams(words):
anagrams = collections.defaultdict(list)
for word in words:
- anagrams[tuple(sorted(word.lower()))].append(word)
+ anagrams[tuple(sorted(word))].append(word)
return list(anagrams.values())

Снежана обнови решението на 15.03.2014 18:10 (преди над 10 години)

import collections
ALPHABET = 'абвгдежзийклмнопрстуфхцчшщьюяъ'
def is_pangram(string):
return len(set([x for x in list(string.lower()) if x in ALPHABET])) == 30
def char_histogram(string):
return dict(collections.Counter(list(string)))
def sort_by(func, arguments):
for i in range(len(arguments)-1):
for i in range(len(arguments)-1):
if func(arguments[i], arguments[i+1]) > 0:
arguments[i], arguments[i+1] = arguments[i+1], arguments[i]
return arguments
def group_by_type(dictionary):
grouped_items = collections.defaultdict(lambda: dict())
for key, value in dictionary.items():
grouped_items[type(key)][key] = value
return dict(grouped_items)
def anagrams(words):
anagrams = collections.defaultdict(list)
for word in words:
- anagrams[tuple(sorted(word))].append(word)
+ anagrams[tuple(sorted(word.lower()))].append(word)
return list(anagrams.values())

Снежана обнови решението на 16.03.2014 23:39 (преди над 10 години)

import collections
+
ALPHABET = 'абвгдежзийклмнопрстуфхцчшщьюяъ'
-def is_pangram(string):
- return len(set([x for x in list(string.lower()) if x in ALPHABET])) == 30
+def is_pangram(phrase):
+ return len(set([x for x in list(phrase.lower()) if x in ALPHABET])) == 30
def char_histogram(string):
- return dict(collections.Counter(list(string)))
+ return collections.Counter(list(string))
def sort_by(func, arguments):
for i in range(len(arguments)-1):
for i in range(len(arguments)-1):
if func(arguments[i], arguments[i+1]) > 0:
arguments[i], arguments[i+1] = arguments[i+1], arguments[i]
return arguments
def group_by_type(dictionary):
- grouped_items = collections.defaultdict(lambda: dict())
+ grouped_items = collections.defaultdict(dict)
for key, value in dictionary.items():
grouped_items[type(key)][key] = value
return dict(grouped_items)
def anagrams(words):
anagrams = collections.defaultdict(list)
for word in words:
- anagrams[tuple(sorted(word.lower()))].append(word)
+ without_signs = sorted(list(filter(lambda x: x.isalpha(), word)))
+ anagrams[tuple(without_signs)].append(word)
return list(anagrams.values())

Снежана обнови решението на 16.03.2014 23:42 (преди над 10 години)

import collections
ALPHABET = 'абвгдежзийклмнопрстуфхцчшщьюяъ'
def is_pangram(phrase):
return len(set([x for x in list(phrase.lower()) if x in ALPHABET])) == 30
def char_histogram(string):
return collections.Counter(list(string))
def sort_by(func, arguments):
for i in range(len(arguments)-1):
for i in range(len(arguments)-1):
if func(arguments[i], arguments[i+1]) > 0:
arguments[i], arguments[i+1] = arguments[i+1], arguments[i]
return arguments
def group_by_type(dictionary):
grouped_items = collections.defaultdict(dict)
for key, value in dictionary.items():
grouped_items[type(key)][key] = value
- return dict(grouped_items)
+ return grouped_items
def anagrams(words):
anagrams = collections.defaultdict(list)
for word in words:
without_signs = sorted(list(filter(lambda x: x.isalpha(), word)))
anagrams[tuple(without_signs)].append(word)
return list(anagrams.values())

Снежана обнови решението на 17.03.2014 00:23 (преди над 10 години)

import collections
ALPHABET = 'абвгдежзийклмнопрстуфхцчшщьюяъ'
def is_pangram(phrase):
return len(set([x for x in list(phrase.lower()) if x in ALPHABET])) == 30
def char_histogram(string):
return collections.Counter(list(string))
def sort_by(func, arguments):
for i in range(len(arguments)-1):
for i in range(len(arguments)-1):
if func(arguments[i], arguments[i+1]) > 0:
arguments[i], arguments[i+1] = arguments[i+1], arguments[i]
return arguments
def group_by_type(dictionary):
grouped_items = collections.defaultdict(dict)
for key, value in dictionary.items():
grouped_items[type(key)][key] = value
return grouped_items
def anagrams(words):
anagrams = collections.defaultdict(list)
for word in words:
- without_signs = sorted(list(filter(lambda x: x.isalpha(), word)))
- anagrams[tuple(without_signs)].append(word)
+ without_signs = filter(lambda x: x.isalpha(), word)
+ anagrams[tuple(sorted(without_signs))].append(word)
return list(anagrams.values())

Снежана обнови решението на 17.03.2014 00:32 (преди над 10 години)

import collections
ALPHABET = 'абвгдежзийклмнопрстуфхцчшщьюяъ'
def is_pangram(phrase):
return len(set([x for x in list(phrase.lower()) if x in ALPHABET])) == 30
def char_histogram(string):
return collections.Counter(list(string))
-def sort_by(func, arguments):
+def sort_by(function, arguments):
for i in range(len(arguments)-1):
for i in range(len(arguments)-1):
- if func(arguments[i], arguments[i+1]) > 0:
+ if function(arguments[i], arguments[i+1]) > 0:
arguments[i], arguments[i+1] = arguments[i+1], arguments[i]
return arguments
def group_by_type(dictionary):
grouped_items = collections.defaultdict(dict)
for key, value in dictionary.items():
grouped_items[type(key)][key] = value
return grouped_items
def anagrams(words):
anagrams = collections.defaultdict(list)
for word in words:
without_signs = filter(lambda x: x.isalpha(), word)
anagrams[tuple(sorted(without_signs))].append(word)
return list(anagrams.values())

Снежана обнови решението на 17.03.2014 09:48 (преди над 10 години)

import collections
ALPHABET = 'абвгдежзийклмнопрстуфхцчшщьюяъ'
+
def is_pangram(phrase):
return len(set([x for x in list(phrase.lower()) if x in ALPHABET])) == 30
+
def char_histogram(string):
return collections.Counter(list(string))
+
def sort_by(function, arguments):
for i in range(len(arguments)-1):
for i in range(len(arguments)-1):
if function(arguments[i], arguments[i+1]) > 0:
arguments[i], arguments[i+1] = arguments[i+1], arguments[i]
return arguments
+
def group_by_type(dictionary):
grouped_items = collections.defaultdict(dict)
for key, value in dictionary.items():
grouped_items[type(key)][key] = value
return grouped_items
+
def anagrams(words):
anagrams = collections.defaultdict(list)
for word in words:
without_signs = filter(lambda x: x.isalpha(), word)
anagrams[tuple(sorted(without_signs))].append(word)
- return list(anagrams.values())
+ return list(anagrams.values())

Снежана обнови решението на 17.03.2014 10:44 (преди над 10 години)

import collections
ALPHABET = 'абвгдежзийклмнопрстуфхцчшщьюяъ'
def is_pangram(phrase):
return len(set([x for x in list(phrase.lower()) if x in ALPHABET])) == 30
-def char_histogram(string):
- return collections.Counter(list(string))
+def char_histogram(sentence):
+ return collections.Counter(list(sentence))
def sort_by(function, arguments):
for i in range(len(arguments)-1):
for i in range(len(arguments)-1):
if function(arguments[i], arguments[i+1]) > 0:
arguments[i], arguments[i+1] = arguments[i+1], arguments[i]
return arguments
def group_by_type(dictionary):
grouped_items = collections.defaultdict(dict)
for key, value in dictionary.items():
grouped_items[type(key)][key] = value
return grouped_items
def anagrams(words):
anagrams = collections.defaultdict(list)
for word in words:
without_signs = filter(lambda x: x.isalpha(), word)
anagrams[tuple(sorted(without_signs))].append(word)
return list(anagrams.values())

Снежана обнови решението на 18.03.2014 21:04 (преди над 10 години)

import collections
ALPHABET = 'абвгдежзийклмнопрстуфхцчшщьюяъ'
def is_pangram(phrase):
return len(set([x for x in list(phrase.lower()) if x in ALPHABET])) == 30
def char_histogram(sentence):
return collections.Counter(list(sentence))
def sort_by(function, arguments):
for i in range(len(arguments)-1):
for i in range(len(arguments)-1):
if function(arguments[i], arguments[i+1]) > 0:
arguments[i], arguments[i+1] = arguments[i+1], arguments[i]
return arguments
def group_by_type(dictionary):
grouped_items = collections.defaultdict(dict)
for key, value in dictionary.items():
grouped_items[type(key)][key] = value
return grouped_items
def anagrams(words):
anagrams = collections.defaultdict(list)
for word in words:
- without_signs = filter(lambda x: x.isalpha(), word)
- anagrams[tuple(sorted(without_signs))].append(word)
+ anagrams[tuple( x for x in sorted(word) if x.isalpha())].append(word)
return list(anagrams.values())

Снежана обнови решението на 18.03.2014 21:05 (преди над 10 години)

import collections
ALPHABET = 'абвгдежзийклмнопрстуфхцчшщьюяъ'
def is_pangram(phrase):
return len(set([x for x in list(phrase.lower()) if x in ALPHABET])) == 30
def char_histogram(sentence):
return collections.Counter(list(sentence))
def sort_by(function, arguments):
for i in range(len(arguments)-1):
for i in range(len(arguments)-1):
if function(arguments[i], arguments[i+1]) > 0:
arguments[i], arguments[i+1] = arguments[i+1], arguments[i]
return arguments
def group_by_type(dictionary):
grouped_items = collections.defaultdict(dict)
for key, value in dictionary.items():
grouped_items[type(key)][key] = value
return grouped_items
def anagrams(words):
anagrams = collections.defaultdict(list)
for word in words:
- anagrams[tuple( x for x in sorted(word) if x.isalpha())].append(word)
+ anagrams[tuple(x for x in sorted(word) if x.isalpha())].append(word)
return list(anagrams.values())

Снежана обнови решението на 19.03.2014 16:17 (преди над 10 години)

import collections
ALPHABET = 'абвгдежзийклмнопрстуфхцчшщьюяъ'
def is_pangram(phrase):
return len(set([x for x in list(phrase.lower()) if x in ALPHABET])) == 30
def char_histogram(sentence):
return collections.Counter(list(sentence))
def sort_by(function, arguments):
for i in range(len(arguments)-1):
for i in range(len(arguments)-1):
if function(arguments[i], arguments[i+1]) > 0:
arguments[i], arguments[i+1] = arguments[i+1], arguments[i]
return arguments
def group_by_type(dictionary):
grouped_items = collections.defaultdict(dict)
for key, value in dictionary.items():
grouped_items[type(key)][key] = value
return grouped_items
def anagrams(words):
anagrams = collections.defaultdict(list)
for word in words:
- anagrams[tuple(x for x in sorted(word) if x.isalpha())].append(word)
+ without_signs = filter(lambda x: x.isalpha(), word.lower())
+ anagrams[tuple(sorted(without_signs))].append(word)
return list(anagrams.values())