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?
Created at: 2020/08/23 14:31; Updated at: 2020/08/24 10:37
The question is resolved.