Aaron Yodaiken Aaron Yodaiken - 4 months ago 8
Python Question

in string, capitalize allcaps words and leave the rest alone

For example, having gone through this procedure the string:

Hello, WORLD, McGisty, you are my HERO THAT I am.


should return/be:

Hello, World, McGisty, you are my Hero That I am.

Answer
>>> x = 'Hello, WORLD, McGisty, you are my HERO THAT I am.'
>>> m = ' '.join(e.capitalize() if e.isupper() else e for e in x.split())
>>> m
'Hello, World, McGisty, you are my Hero That I am.'