将一个英文语句以单词为单位逆序排放。例如“I am a boy”,逆序排放后为“boy a am I”
所有单词之间用一个空格隔开,语句中除了英文字母外,不再包含其他字符
数据范围:输入的字符串长度满足
注意本题有多组输入
将一个英文语句以单词为单位逆序排放。例如“I am a boy”,逆序排放后为“boy a am I”
输入一个英文语句,每个单词用空格隔开。保证输入只包含空格和字母。
得到逆序的句子
I am a boy
boy a am I
nowcoder
nowcoder
import re words = input("") words = re.sub(" +"," ",words) words_list = words.split(" ") res = " ".join(words_list[::-1]) print(res)
str1 = input() list1 = str1.split(' ') for i in list1[::-1]: print(i ,end=' ')
con = input().split(' ') con = con[::-1] print(' '.join(con))
str1 = input().split() for i in reversed(str1): print(i,end=' ')