Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
replace().split() solution in Clear category for First Word by mathieu.roesch
def first_word(text: str) -> str:
text = text.replace(',',' ').replace('.', ' ').split()
word = text[0]
return word
if __name__ == '__main__':
print("Example:")
print(first_word("Hello world"))
# These "asserts" are used for self-checking and not for an auto-testing
print(first_word("Hello world"))# == "Hello"
print(first_word(" a word "))# == "a"
print(first_word("don't touch it"))# == "don't"
print(first_word("greetings, friends"))# == "greetings"
print(first_word("... and so on ..."))# == "and"
print(first_word("hi"))# == "hi"
print(first_word("Hello.World"))# == "Hello"
print("Coding complete? Click 'Check' to earn cool rewards!")
July 12, 2018
Comments: