0
Been stuck on generator text split
Given a string as input, create a generator function that splits the string into separate words and outputs the resulting list. Sample Input This is some text Sample Output ['This', 'is', 'some', 'text']
6 Antworten
+ 5
Tamekka You should show where you got stuck, by adding in your question description:
1. A link to your code in Code Playground
2. An explanation of your difficulties
This is how we know what to help you on.
That said, I recommend redoing the lesson on generators.
+ 5
SoloProg ,
the request is to create a generator function, that splits ....
your code is a NOT a generator, it does just uses print() with input() and split() inside.
a generator function is using the yield statement
here is a simple generator function, that capitalizes the first letter of each word:
def string_caps(string):
lst = string.split()
for item in lst:
yield item.capitalize()
text = " hello out there"
for word in string_caps(text):
print(word)
+ 3
SoloProg Why do you insist in giving finished code as answer, after so many warnings? Do you really want to avoid people to follow steps, finding solutions, then learning?
0
Can you please help . for some reason this one gets me
- 1
x = input()
print(x.split())