This method converts an intercapitalized name such as “DarkSlateGray” to its lowercased, space-embedded form such as “dark slate gray”.
# - - - P i c k L i s t . _ _ l o w e r i z e def __lowerize ( self, name ): """Convert an intercapitalized color name to lowercase form. [ name is a string -> return name with all letters lowercased, and single spaces inserted at each lowercase->uppercase transition ] """
First we break the name up into a list of individual characters.
Then we work through the gaps between characters, adding a
space after that gap if there was a lowercase-uppercase
transition there. Finally, the
reassembles the pieces into a string.
#-- 1 -- # [ letters := a list of the characters in name ] letters = list ( name ) #-- 2 -- # [ letters := letters with a space prefixed to any # uppercase letter preceded by a lowercase letter ] for i in range ( 1, len ( letters ) ): if ( letters[i-1].islower() and letters[i].isupper() ): letters[i] = " " + letters[i] #-- 3 -- return "".join ( letters )