Решение на doge от Евгени Евлогиев

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

Към профила на Евгени Евлогиев

Резултати

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

Код

def wow_such_much(start, end):
result = []
for i in range(start, end):
if i % 15 == 0:
result.append('suchmuch')
elif i % 5 == 0:
result.append('much')
elif i % 3 == 0:
result.append('such')
else:
result.append(str(i))
return result
def count_doge_words(sentence):
count = 0
parasite_words = ['wow', 'lol', 'so', 'such', 'much', 'very']
for word in sentence.split(' '):
if word in parasite_words:
count += 1
return count

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

...............
----------------------------------------------------------------------
Ran 15 tests in 0.010s

OK

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

Евгени обнови решението на 09.03.2014 22:28 (преди около 10 години)

+def wow_such_much(start, end):
+ result = []
+ for i in range(start, end):
+ if i % 3 == 0 and i % 5 == 0:
+ result.append('suchmuch')
+ elif i % 5 == 0:
+ result.append('much')
+ elif i % 3 == 0:
+ result.append('such')
+ else:
+ result.append(str(i))
+ return result
+
+
+def count_doge_words(sentence):
+ count = 0
+ list_parasite = ['wow', 'lol', 'so', 'such', 'much', 'very']
+ list_of_words = sentence.split(' ')
+ list_of_words_len = len(list_of_words)
+ for i in range(0, list_of_words_len):
+ if list_of_words[i] in list_parasite:
+ count += 1
+ return count

Евгени обнови решението на 10.03.2014 00:42 (преди около 10 години)

def wow_such_much(start, end):
result = []
for i in range(start, end):
- if i % 3 == 0 and i % 5 == 0:
+ if i % 15 == 0:
result.append('suchmuch')
elif i % 5 == 0:
result.append('much')
elif i % 3 == 0:
result.append('such')
else:
result.append(str(i))
return result
def count_doge_words(sentence):
count = 0
list_parasite = ['wow', 'lol', 'so', 'such', 'much', 'very']
- list_of_words = sentence.split(' ')
- list_of_words_len = len(list_of_words)
- for i in range(0, list_of_words_len):
- if list_of_words[i] in list_parasite:
+ for i in range(0, len(sentence.split(' '))):
+ if sentence.split(' ')[i] in list_parasite:
count += 1
return count

в случая проблема е друг: циклиш по индексите на един списък вместо по обектите му..

Python е достатъчно умен, за да можеш да му кажеш следното:

for item in my_tems:
    do_somethig(item)

вместo:

for index in range(len(my_items)):
    do_something(my_items[index])

Евгени обнови решението на 11.03.2014 22:01 (преди около 10 години)

def wow_such_much(start, end):
result = []
for i in range(start, end):
if i % 15 == 0:
result.append('suchmuch')
elif i % 5 == 0:
result.append('much')
elif i % 3 == 0:
result.append('such')
else:
result.append(str(i))
return result
def count_doge_words(sentence):
count = 0
- list_parasite = ['wow', 'lol', 'so', 'such', 'much', 'very']
- for i in range(0, len(sentence.split(' '))):
- if sentence.split(' ')[i] in list_parasite:
+ parasite_words = ['wow', 'lol', 'so', 'such', 'much', 'very']
+ for word in sentence.split(' '):
+ if word in parasite_words:
count += 1
return count