题解 | #单词倒排#
单词倒排
https://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
''' from re import L l=list('I am a student'.split()) l1=reversed(l) print(l,l1) #print(ord('a'),ord('z'),ord('A'),ord('Z')) ''' ''' while True: try: sentence=input() for i in sentence: if 65<=ord(i)<=90 or 97<=ord(i)<=122: sentence else: sentence=sentence.replace(i,' ') # for循环中,a=a.replace(),不能只写a.replace() #print(sentence) sen_list=list(sentence.split()) sen_list.reverse() # list.reverse()原地逆序 print(' '.join(sen_list)) except: break ''' while True: try: sentence=input() for i in sentence: if 65<=ord(i)<=90 or 97<=ord(i)<=122: sentence else: sentence=sentence.replace(i,' ') #print(sentence) #print(sentence[::-1]) sentence1=sentence.split() print(*sentence1[::-1]) # *[list] 列表解包;[::-1]逆序 except: break