PYHTON将文本内容还原成正常顺序2020-10-05

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

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值