题解 | #单词倒排#
单词倒排
https://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
instr = input()
while True:
try:
#第一步,筛选非英文字母,并将非构成单词的字符转换为间隔符’ ‘
str = ''
for i in instr:
if i.isalpha():
str += i
else:
str += ' '
list = str.split(' ')
#第二步,先删除新字符串中的所有空字符,然后倒序
new_list = []
for k in list:
if k != '':
new_list.append(k)
new_list = new_list[::-1]
#转化为字符串输出,单词间以一个间隔符为隔断
outstr = ' '.join(new_list)
print(outstr)
break
except:
break