全部评论
def reverse_words(sentence): words = [] current_word = [] for char in sentence: if char == ' ': if current_word: words.append(''.join(current_word)) current_word = [] else: current_word.append(char) if current_word: words.append(''.join(current_word)) reversed_sentence = '' for i in range(len(words) - 1, -1, -1): reversed_sentence += words[i] if i != 0: reversed_sentence += ' ' return reversed_sentence
相关推荐
点赞 评论 收藏
分享