PYHTON將文本內容還原成正常順序
原文本內容為
.egassem siht htiw yad s’enoemos nethgirb ot ytinutroppo eht no tuo ssim tsuj lliw uoy,uoy ot neppah lliw dab gnihton,yrrow t’nod ,t’nod uoy fi dnA.pihsdneirf rieht etaicerppa uoy taht wonk meht tel ot tnaw uoy ohw esoht ot,nwod yllaer era uoy nehw sgniht fo edis rethgirb eht ees uoy ekam taht esoht ot,ti deen yllaer uoy nehw elims uoy ekam ohw esoht ot,rehtona ro yaw eno ni efil ruoy dehcuot evah ohw esoht ot,uoy ot gnihtemos naem ohw elpoep esoht ot egassem siht dnes esaelP .gniyrc si uoy dnuora enoyreve dna gnilims si ohw eno eht er'uoy,eid uoy nehw taht os efil ruoy eviL.gnilims saw uoy dnuora enoyreve dna gniyrc erew uoy,nrob erew uoy nehW .sehcatraeh dna seruliaf tsap ruoy fo og tel uoy litnuefil ni llew no og t’nac uoy ,tsap nettogrof a no desab eb syawla lliw erutuf tsethgirb ehT.raet a htiw sdne dna ssik a htiw sworg,elims a htiw snigeb evoL.sevil rieht dehcuot evah ohw elpoep fo ecnatropmi eht etaicerppa nac yeht ylno rof,deirt evah ohw esoht dna,dehcraes evah ohw esoht ,truh ohw esoht,yrc ohw esoht rof seil ssenippaH.yaw rieht gnola semoc taht gnihtyreve fo tsom eht ekam tsuj yeht;gnihtyreve fo tseb eht evah ylirassecen t’nod elpoep fo tseippah ehT .oot ,nosrep rehto eht struh ylbaborp ti,uoy struh ti taht leef uoy fI.seohs’srehto ni flesruoy tup syawlA ?yppah uoy ekam ot epoh hguone,namuh uoy peek ot worros hguone,gnorts uoy ekam ot slairt hguone,teews uoy ekam ot ssenippah hguone evah uoy yaM .od ot tnaw uoy sgniht eht lla od ot ecnahc eno dna efil eno ylno evah uoy esuaceb,eb ot tnaw uoy tahw eb;og ot tnaw uoy erehw og;maerd ot tnaw uoy tahw maerD !laer rof meht guh dna smaerd ruoy morf meht kcip ot tnaw tsuj uoy taht hcum os enoemos ssim uoy nehw efil ni stnemom era erehT
這篇文章一看就是將所有字串反轉且字串中單詞也反轉了所以要還原成正常順序就要進行反轉
def gettext():
txt=open("input.txt","r",encoding='UTF-8').read()
txt=txt.lower()
for ch in '!"#$%&()*+,-./:;<=>?@[\\]^_`{|},~ ‘’':
txt=txt.replace(ch," ")
return txt
rtxt=gettext()
str_dst=rtxt.split()#以空格符為分隔符,將各單詞取出來放在串列中
result = ""
for c in str_dst:#拆字
new=c[::-1]#將字串中的單詞反轉
result =new+result#將字串反轉
print(result)
反轉后的內容為
therearemomentsinlifewhenyoumisssomeonesomuchthatyoujustwanttopickthemfromyourdreamsandhugthemforrealdreamwhatyouwanttodreamgowhereyouwanttogobewhatyouwanttobebecauseyouhaveonlyonelifeandonechancetodoallthethingsyouwanttodomayyouhaveenoughhappinesstomakeyousweetenoughtrialstomakeyoustrongenoughsorrowtokeepyouhumanenoughhopetomakeyouhappyalwaysputyourselfinothersshoesifyoufeelthatithurtsyouitprobablyhurtstheotherpersontoothehappiestofpeopledontnecessarilyhavethebestofeverythingtheyjustmakethemostofeverythingthatcomesalongtheirwayhappinessliesforthosewhocrythosewhohurtthosewhohavesearchedandthosewhohavetriedforonlytheycanappreciatetheimportanceofpeoplewhohavetouchedtheirliveslovebeginswithasmilegrowswithakissandendswithatearthebrightestfuturewillalwaysbebasedonaforgottenpastyoucantgoonwellinlifeuntilyouletgoofyourpastfailuresandheartacheswhenyouwerebornyouwerecryingandeveryonearoundyouwassmilingliveyourlifesothatwhenyoudieyou'retheonewhoissmilingandeveryonearoundyouiscryingpleasesendthismessagetothosepeoplewhomeansomethingtoyoutothosewhohavetouchedyourlifeinonewayoranothertothosewhomakeyousmilewhenyoureallyneedittothosethatmakeyouseethebrightersideofthingswhenyouarereallydowntothosewhoyouwanttoletthemknowthatyouappreciatetheirfriendshipandifyoudontdontworrynothingbadwillhappentoyouyouwilljustmissoutontheopportunitytobrightensomeonesdaywiththismessage
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/162238.html
標籤:其他
上一篇:深入理解cookie和session,這一篇就夠了(建議收藏)
下一篇:py入門筆記1
