return (len(s.split()[-1]) if len(s.split()) >= 1 else 0)
You call .split() twice in there - brings execution speed down. I had a very similar solution - split it out from one line and it beats 98% :)
words = s.split()
if not words:
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.