第1个回答
用户4***62019.10.21回答#倒数第二行,就是你要的语句:defstr_abc(list_x):#自定义函数k_k=[]i=0k=0whilei<len(list_x):iflist_x[i:i+1]=='':zz=list_x[k:i]#依次取单词#print(zz)k_k.append(zz)#print(k_k)k=i+1i=i+1k_k.append(list_x[k:i-1])#取最后一个单词#print(k_k)returnk_k#------------------------------------------------------------------------------------a=['Butsoftwhatlightthroughyonderwindowbreaks\n','ItistheeastandJulietisthesun\n','Arisefairsunandkilltheenviousmoon\n','Whoisalreadysickandpalewithgrief\n']k_ok=(str_abc(a[0]))+(str_abc(a[1]))+(str_abc(a[2]))+(str_abc(a[3]))#调用函数str_abck_ok.sort()#排序k_ok=sorted(set(k_ok),key=k_ok.index)#sortedoutput清除多余的相同元素。print(k_ok)