Решение на doge от Йордан Петров

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

Към профила на Йордан Петров

Резултати

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

Код

def wow_such_much(start, end):
"""
Build list of strings with all the numbers from start to end
where the numbers which can be divisible to 3 are replaced with 'such',
those that are divisible to 5 are replaced with 'much' and those
that are divisible to 3 and 5 are replaced with 'suchmuch'
Args:
start : the starting number
end : the end number
Returns:
such_much_list: list of strings where the qualified numbers are replaced
with such, much or suchmuch
"""
such_much_list = []
for number in range(start, end):
string_to_append = ''
if number % 3 == 0:
string_to_append += 'such'
if number % 5 == 0:
string_to_append += 'much'
if not string_to_append:
string_to_append = str(number)
such_much_list.append(string_to_append)
return such_much_list
def count_doge_words(input_str):
"""
Count the frequency of 'parasitic' doge words in a string
Args:
input_str : input string
Returns:
sum of the frequencies of all 'parasitic' doge words in the input string
"""
doge_words = {'very', 'wow', 'lol', 'much', 'so', 'such'}
input_words = [i for i in input_str.split()]
return sum(input_words.count(word) for word in doge_words)

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

...............
----------------------------------------------------------------------
Ran 15 tests in 0.009s

OK

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

Йордан обнови решението на 12.03.2014 12:27 (преди над 10 години)

+def wow_such_much(start, end):
+ """
+ Build list of strings with all the numbers from start to end
+ where the numbers which can be divisible to 3 are replaced with 'such',
+ those that are divisible to 5 are replaced with 'much' and those
+ that are divisible to 3 and 5 are replaced with 'suchmuch'
+
+ Args:
+ start : the starting number
+ end : the end number
+
+ Returns:
+ such_much_list: list of strings where the qualified numbers are replaced
+ with such, much or suchmuch
+ """
+ such_much_list = []
+ for number in range(start, end):
+ string_to_append = ''
+ if number % 3 == 0:
+ string_to_append += 'such'
+ if number % 5 == 0:
+ string_to_append += 'much'
+ if not string_to_append:
+ string_to_append = str(number)
+ such_much_list.append(string_to_append)
+ return such_much_list
+
+def count_doge_words(input_str):
+ """
+ Count the frequency of 'parasitic' doge words in a string
+
+ Args:
+ input_str : input string
+
+ Returns:
+ sum of the frequencies of all 'parasitic' doge words in the input string
+ """
+ doge_words = {'very', 'wow', 'lol', 'much', 'so', 'such'}
+ input_words = [i for i in input_str.split()]
+ return sum(input_words.count(word) for word in doge_words)