Use for, .split()
, and if to create a Statement that will print out words that start with 's':
st = 'Print only the words that start with s in this sentence'
Use for, .split()
, and if to create a Statement that will print out words that start with 's':
st = 'Print only the words that start with s in this sentence'
Try this instead
st = 'Print only the words that start with s in this sentence'
Answer = [word for word in st.split() if word[0] == 's']
print(Answer)
Split the list into Strings with .split()
. Use " "
as a separator because you want spaces to separate the words.
st = "Print only the words that start with s in this sentence"
words = []
for word in st.split(" "):
if word.startswith("s"):
words.append(word)
print(words)