469,602 Members | 1,741 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

Write a python program that splits a sentence into words

Hi
I don't have much experience on python coding. Can someone give me a answer for this ques.
Question: Write a python program that splits a sentence into words. Change the first and last letter of each word into uppercase and display them.
For example if we type input as hello,world
The output must be:
HellO
WorlD
Oct 19 '21 #1
2 3912
dev7060
519 Expert 512MB
Hi
I don't have much experience on python coding. Can someone give me a answer for this ques.
Question: Write a python program that splits a sentence into words. Change the first and last letter of each word into uppercase and display them.
For example if we type input as hello,world
The output must be:
HellO
WorlD
What have you done so far?
Oct 19 '21 #2
SioSio
264 256MB
Expand|Select|Wrap|Line Numbers
  1. import re
  2. txt = 'hello,world hello/world hello+world hello-world'
  3. new_word = []
  4. for word in re.split('[ ,+-/]',txt):
  5.     new_word = word[0].upper() + word[1:len(word)-1] + word[len(word)-1].upper()
  6.     print (new_word)
Oct 21 '21 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Peter McKeown | last post: by
5 posts views Thread by balck05 | last post: by
reply views Thread by guiromero | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.