How to uppercase the first and last letter of each word in Python

1 Answer

0 votes
def capitalize_first_last(s):
    return " ".join(word[:-1].capitalize() + word[-1].capitalize() for word in s.split())
 
 
s = "python isan interpreted general purpose programming language"
 
print(capitalize_first_last(s))
 
  
 
 
 
      
'''
run:
      
PythoN IsaN InterpreteD GeneraL PurposE ProgramminG LanguagE
  
'''

 



answered Nov 2, 2021 by avibootz
...