-
Notifications
You must be signed in to change notification settings - Fork 1
/
047_Sentence Smash.py
68 lines (45 loc) · 1.55 KB
/
047_Sentence Smash.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
Codewars Coding Challenge
Day 47/366
Level : 8kyu
Sentence Smash
Write a function that takes an array of words and smashes them together into a sentence and returns the sentence. You can ignore any need to sanitize words or add punctuation, but you should add spaces between each word. Be careful, there shouldn't be a space at the beginning or the end of the sentence!
Example
['hello', 'world', 'this', 'is', 'great'] => 'hello world this is great'
def smash(words):
return ""
https://www.codewars.com/kata/53dc23c68a0c93699800041d/train/python
"""
# My Solution
def smash(words):
str_words = ""
for i in range(len(words)):
str_words += words[i] + " "
return str_words.rstrip()
print(smash(["Hello", "World"]))
"""
Sample Tests
import codewars_test as test
from solution import smash
@test.describe("smash")
def _():
@test.it("Should return empty string for empty array.")
def _():
test.assert_equals(smash([]), "")
@test.it("One word example should return the word.")
def _():
test.assert_equals(smash(["hello"]), "hello")
@test.it("Multiple words should be separated by spaces.")
def _():
test.assert_equals(smash(["hello", "world"]), "hello world")
test.assert_equals(smash(["hello", "amazing", "world"]), "hello amazing world")
test.assert_equals(smash(["this", "is", "a", "really", "long", "sentence"]), "this is a really long sentence")
"""
"""
Perfect Solutions From Codewars
=1=
def smash(words):
return " ".join(words)
=2=
smash = ' '.join
"""