Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,038 questions

40,803 answers

573 users

How to reverse the middle words of a string in Python

1 Answer

0 votes
def reverse_middle_words(s): 
    lst = [s for s in s.split(' ')]  
  
    tmp = lst[0]
      
    for i in range(1, len(lst) - 1): 
        tmp += " " + lst[i][::-1]
  
    tmp += " " + lst[len(lst) - 1] 

    return tmp;
  


s = "c++ python java vb"

s = reverse_middle_words(s) 

print(s)


'''
run:

c++ nohtyp avaj vb

'''

 





answered Dec 12, 2019 by avibootz

Related questions

1 answer 88 views
1 answer 89 views
1 answer 110 views
1 answer 79 views
1 answer 104 views
...