Computer Science

Write a function WordsList(S), where S is a string. The function returns a list, named Words, that stores all the words from the string which contain 'r'.

For example, if S is "Dew drops were shining in the morning", then the list Words should be: ['drops', 'were', 'morning']

Python

Python List Manipulation

1 Like

Answer

def WordsList(S):
    words = S.split()
    Words = []
    for word in words:
        if 'r' in word:
           Words.append(word)
    return Words

S = "Dew drops were shining in the morning"
print(WordsList(S))

Output

['drops', 'were', 'morning']

Answered By

2 Likes


Related Questions