while True:
    try:
        string = input().strip()
        for word in string:
            if not word.isalpha():
                string = string.replace(word, " ")// 将非alpha的字符用空格取代
        string =string.split(" ")//切割后形成数组(多空格的话里面也有空字符)
        new_str = list(filter(None,string))// filter(None,string)可过滤掉空字符
        print(" ".join(new_str[::-1]))
    except:
        break

消除数组空字符的方法:

  1. filter(None, your_list)
while '' in your_list:
	your_list.remove(' ')
[x for x in your_list if x!='']