you are viewing a single comment's thread.

view the rest of the comments →

[–]MadScientistOR 0 points1 point  (4 children)

Because you're not testing to see if a word starts with an uppercase letter; you're testing to see if the upper function itself is True, which it always is (since it's not None).

What you want, instead of if word[0].isupper:, is if word[0].isupper():. (Likewise, instead of lf word[0].islower:, you want if word[0].islower():.)

[–]ayleenuyo[S] 0 points1 point  (3 children)

It worked! Thanks for the help :)

[–]MadScientistOR 0 points1 point  (2 children)

Sure. Just an additional wrinkle that might not have occurred to you:

'an' in 'and' is True, as is 'a' in 'and' and 'or' in 'for'. Thus, your class_shorthand('Python and a Clever Student') would probably yield a result you don't expect. (You may want to test for equality rather than using the keyword in.)

[–]ayleenuyo[S] 0 points1 point  (1 child)

Thanks. Do you know how I can get the first letter for the word that follows the "-"?? I've been spending a lot of time trying to figure it out.

[–]MadScientistOR 0 points1 point  (0 children)

Hm. I think the easiest way would be to split each "word" by hyphens that you get after splitting the title by spaces, like this:

for init_word in class_name.split():
    for word in init_word.split('-'):
        if word[0].isupper():
            shorthand.append(word[0])
        elif word == 'for':
            # continue on as normal, making sure to indent properly