题解 | #单词倒排#
单词倒排
https://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
while True: try: sen = input() output = '' for i in sen: if i.isalpha(): #如果字符是字母则添加到output output += i else: output += ' ' #如果不是字母则添加空格到output output = output.split()[::-1] #分隔空格,得到留下的单词的list,再反转顺序 for ele in output: print(ele,end=' ') #输出的时候加上空格 except: break