Light Mode
Dark Mode
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?

  • feedback
Created: Aug. 23, 2020, 2:31 p.m.
Updated: Aug. 24, 2020, 10:37 a.m.
0
6
User avatar
Sarnix