April 19th, 2013, 10:38 PM
Need help separating a string by uppercase letters
My final program for class is requiring me to separate a string that has mixed upper and lower case characters. Such as "StopAndSmellTheRoses"
April 19th, 2013, 11:25 PM
Are you supposed to use regular expressions or do it manually?
If you are allowed to use the re module then it is a one-liner using re.findall(). If you are not using regular expressions then you will probably want to use the ord() built-in to check if a letter is in a given range.
April 19th, 2013, 11:28 PM
According to my instructor we are to use the spit expression
Originally Posted by Mekire
April 19th, 2013, 11:50 PM
Actually you won't need ord. You can use the string method isupper(). If you are really supposed to do this with split then I would recommend creating a new string. Iterate through your original string, and if the letter is upper-case concatenate a space plus the character to the new one; if the character is lower case, then only concatenate the character. After you have created this string split will work.