import reloc = ' Ny Us'print(re.sub('( |^)[A-Z][a-z](?=$| )', lambda m: m.group(0).upper(), loc) )
Standard input is empty
NY US
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!