Program 80: Write a program in Python to create a list of words which start and end with the same letter from a given string S="window apple wow table taught pencil comic'. The output should be: ['window', 'wow', 'taught', 'comic']
S = "window apple wow table taught pencil comic"
# Split the string into words
words = S.split()
# Create list of words starting and ending with same letter
result = []
for word in words:
if word[0] == word[-1]:
result.append(word)
# Display the result
print(result)
Output:
['window', 'wow', 'taught', 'comic']
No comments:
Post a Comment