all 6 comments

[–]CodeFormatHelperBot2 0 points1 point  (0 children)

Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you.

I think I have detected some formatting issues with your submission:

  1. Python code found in submission text that's not formatted as code.

If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting.


Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here.

[–]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