Решение на Пет функции от Божидар Карааргиров

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

Към профила на Божидар Карааргиров

Резултати

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

Код

def is_pangram(sentence):
# Add all letters from the bulgarian alphabet(i is their unicode)
alphabet = {chr(i) for i in range(1040, 1072) if i != 1067 and i != 1069}
sentence = sentence.upper()
for letter in sentence:
alphabet.discard(letter)
return alphabet == set()
def char_histogram(text):
from collections import Counter
character_count = Counter(text)
return character_count
def sort_by(func, arguments):
if len(arguments) < 2:
return arguments
stop_iteration = False
while not stop_iteration:
stop_iteration = True
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]
stop_iteration = False
return arguments
def group_by_type(dictionary):
type_dictionary = {}
for key in dictionary.keys():
if type(key) not in type_dictionary:
type_dictionary[type(key)] = {}
type_dictionary[type(key)][key] = dictionary[key]
return type_dictionary
def anagrams(words):
anagramatic_words = {}
for word in words:
letters = [letter.lower() for letter in word if letter.isalpha()]
letters.sort()
letters = tuple(letters)
if letters in anagramatic_words.keys():
anagramatic_words[letters].append(word)
else:
anagramatic_words[letters] = [word]
return list(anagramatic_words.values())

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

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

OK

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

Божидар обнови решението на 17.03.2014 12:57 (преди около 10 години)

+def is_pangram(sentence):
+ # Add all letters from the bulgarian alphabet(i is their unicode)
+ alphabet = set()
+ for i in range(1040, 1072):
+ alphabet.add(chr(i))
+ # remove each letter from sentence from the alphabet set
+ sentence.upper()
+ for letter in sentence:
+ alphabet.discard(letter)
+ # if no letters are left in the alphabet than all have been used
+ return alphabet == set()
+
+
+def char_histogram(text):
+ character_count = {}
+ for character in text:
+ if character in character_count:
+ character_count[character] += 1
+ else:
+ character_count[character] = 1
+
+ return character_count
+
+
+def sort_by(func, arguments):
+ # trivial check
+ if len(arguments) < 2:
+ return arguments
+
+ stop_iteration = False
+ while not stop_iteration:
+ stop_iteration = True
+ 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]
+ stop_iteration = False
+
+ return arguments
+
+
+def group_by_type(dictionary):
+ type_dictionary = {}
+ for key in dictionary.keys():
+ if type(key) not in type_dictionary:
+ type_dictionary[type(key)] = {}
+ type_dictionary[type(key)][key] = dictionary[key]
+
+ return type_dictionary
+
+
+def anagrams(words):
+ anagramatic_words = {}
+ for word in words:
+ letters = [letter for letter in word if letter.isalpha()]
+ letters.sort()
+ letters = tuple(letters)
+ if letters in anagramatic_words.keys():
+ anagramatic_words[letters].append(word)
+ else:
+ anagramatic_words[letters] = [word]
+
+ return list(anagramatic_words.values())

Божидар обнови решението на 18.03.2014 08:07 (преди около 10 години)

def is_pangram(sentence):
# Add all letters from the bulgarian alphabet(i is their unicode)
alphabet = set()
for i in range(1040, 1072):
alphabet.add(chr(i))
# remove each letter from sentence from the alphabet set
sentence.upper()
for letter in sentence:
alphabet.discard(letter)
# if no letters are left in the alphabet than all have been used
return alphabet == set()
def char_histogram(text):
character_count = {}
for character in text:
if character in character_count:
character_count[character] += 1
else:
character_count[character] = 1
return character_count
def sort_by(func, arguments):
# trivial check
if len(arguments) < 2:
return arguments
stop_iteration = False
while not stop_iteration:
stop_iteration = True
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]
stop_iteration = False
return arguments
def group_by_type(dictionary):
type_dictionary = {}
for key in dictionary.keys():
if type(key) not in type_dictionary:
type_dictionary[type(key)] = {}
type_dictionary[type(key)][key] = dictionary[key]
return type_dictionary
def anagrams(words):
anagramatic_words = {}
for word in words:
+ word.lower()
letters = [letter for letter in word if letter.isalpha()]
letters.sort()
letters = tuple(letters)
if letters in anagramatic_words.keys():
anagramatic_words[letters].append(word)
else:
anagramatic_words[letters] = [word]
return list(anagramatic_words.values())

Божидар обнови решението на 18.03.2014 08:10 (преди около 10 години)

def is_pangram(sentence):
# Add all letters from the bulgarian alphabet(i is their unicode)
alphabet = set()
for i in range(1040, 1072):
alphabet.add(chr(i))
# remove each letter from sentence from the alphabet set
sentence.upper()
for letter in sentence:
alphabet.discard(letter)
# if no letters are left in the alphabet than all have been used
return alphabet == set()
def char_histogram(text):
character_count = {}
for character in text:
if character in character_count:
character_count[character] += 1
else:
character_count[character] = 1
return character_count
def sort_by(func, arguments):
# trivial check
if len(arguments) < 2:
return arguments
stop_iteration = False
while not stop_iteration:
stop_iteration = True
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]
stop_iteration = False
return arguments
def group_by_type(dictionary):
type_dictionary = {}
for key in dictionary.keys():
if type(key) not in type_dictionary:
type_dictionary[type(key)] = {}
type_dictionary[type(key)][key] = dictionary[key]
return type_dictionary
def anagrams(words):
anagramatic_words = {}
for word in words:
- word.lower()
- letters = [letter for letter in word if letter.isalpha()]
+ letters = [letter.lower() for letter in word if letter.isalpha()]
letters.sort()
letters = tuple(letters)
if letters in anagramatic_words.keys():
anagramatic_words[letters].append(word)
else:
anagramatic_words[letters] = [word]
return list(anagramatic_words.values())
  • # trivial check е пример за напълно ненужен коментар. Попринцип, код написан на Python трябва да се самодокументира, така че повечето коментари са показател за усложнено решение.
  • sentence.upper() не прави нищо, освен ако не го assign-неш обратно към sentence: sentence = sentence.upper()

Божидар обнови решението на 18.03.2014 16:03 (преди около 10 години)

def is_pangram(sentence):
# Add all letters from the bulgarian alphabet(i is their unicode)
- alphabet = set()
- for i in range(1040, 1072):
- alphabet.add(chr(i))
- # remove each letter from sentence from the alphabet set
- sentence.upper()
+ alphabet = {chr(i) for i in range(1040, 1072) if i != 1067 and i != 1069}
+ sentence = sentence.upper()
for letter in sentence:
alphabet.discard(letter)
- # if no letters are left in the alphabet than all have been used
return alphabet == set()
def char_histogram(text):
character_count = {}
for character in text:
if character in character_count:
character_count[character] += 1
else:
character_count[character] = 1
return character_count
def sort_by(func, arguments):
- # trivial check
if len(arguments) < 2:
return arguments
stop_iteration = False
while not stop_iteration:
stop_iteration = True
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]
stop_iteration = False
return arguments
def group_by_type(dictionary):
type_dictionary = {}
for key in dictionary.keys():
if type(key) not in type_dictionary:
type_dictionary[type(key)] = {}
type_dictionary[type(key)][key] = dictionary[key]
return type_dictionary
def anagrams(words):
anagramatic_words = {}
for word in words:
letters = [letter.lower() for letter in word if letter.isalpha()]
letters.sort()
letters = tuple(letters)
if letters in anagramatic_words.keys():
anagramatic_words[letters].append(word)
else:
anagramatic_words[letters] = [word]
return list(anagramatic_words.values())

Божидар обнови решението на 18.03.2014 19:57 (преди около 10 години)

def is_pangram(sentence):
# Add all letters from the bulgarian alphabet(i is their unicode)
alphabet = {chr(i) for i in range(1040, 1072) if i != 1067 and i != 1069}
sentence = sentence.upper()
for letter in sentence:
alphabet.discard(letter)
return alphabet == set()
def char_histogram(text):
- character_count = {}
- for character in text:
- if character in character_count:
- character_count[character] += 1
- else:
- character_count[character] = 1
+ from collections import Counter
+ character_count = Counter(text)
return character_count
def sort_by(func, arguments):
if len(arguments) < 2:
return arguments
stop_iteration = False
while not stop_iteration:
stop_iteration = True
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]
stop_iteration = False
return arguments
def group_by_type(dictionary):
type_dictionary = {}
for key in dictionary.keys():
if type(key) not in type_dictionary:
type_dictionary[type(key)] = {}
type_dictionary[type(key)][key] = dictionary[key]
return type_dictionary
def anagrams(words):
anagramatic_words = {}
for word in words:
letters = [letter.lower() for letter in word if letter.isalpha()]
letters.sort()
letters = tuple(letters)
if letters in anagramatic_words.keys():
anagramatic_words[letters].append(word)
else:
anagramatic_words[letters] = [word]
return list(anagramatic_words.values())