#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    2
    Rep Power
    0

    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"
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    191
    Rep Power
    2
    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.

    -Mek
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    2
    Rep Power
    0
    Originally Posted by Mekire
    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.

    -Mek
    According to my instructor we are to use the spit expression
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    191
    Rep Power
    2
    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.

    -Mek

IMN logo majestic logo threadwatch logo seochat tools logo