def smart_capwords(s, sep=None):
 words = s.split(sep)
 for (i, word) in enumerate(words):
  if all((x.islower() for x in word)):
   words[i] = word.capitalize()
 return (sep or ' ').join(words)

def smart_capwords ( s , sep = None ) : words = s . split ( sep ) for ( i , word ) in enumerate ( words ) : if all ( ( x . islower ( ) for x in word ) ) : words [ i ] = word . capitalize ( ) return ( sep or ' ' ) . join ( words )
like string .