• first word solve

 

LS

I came up with a solution, so I thought.

def first_word(text: str) -> str:
    return text.strip(',').strip('.').lstrip(' ').partition(' ')[0]

The weird thing is, it is not the right solution because if you would use it it would produce "greetings,", so the comma would not have been stripped.

assert first_word("greetings, friends") == "greetings"

Why doesn't strip(',') strip the comma?

6