loading...

re: Daily Challenge #263 - Reverse Words VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Well done! It could also be return ' '.join(word[::-1] for word in sentence.split() if not word.isspace())
 

I think this would fail with doubles spaces in a sentence...

That's true :( looks like the right implementation is

def reverse_words(sentence: str) -> str:
    return ' '.join(word[::-1] for word in sentence.split())

you don't need to use (' ') to split by spaces :)

That's what happens when you write too much js code 😅 edited thanks!

code of conduct - report abuse