字符串操作,英文词频统计预处理
Posted pybblog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了字符串操作,英文词频统计预处理相关的知识,希望对你有一定的参考价值。
1.字符串操作:
身份证号解析
ID=input("请输入身份证号:") year=ID[6:10] mouth=ID[10:12] day=ID[12:14] if(int(ID[16])%2==0): sex="女" else: sex="男" print("出生日期为:%s年%s月%s日 性别:%s"%(year,mouth,day,sex))
凯撒密码
plaincode=input("请输入源码:") a=ord(‘a‘) z=ord(‘z‘) A=ord(‘A‘) Z=ord(‘Z‘) for i in plaincode: if a<=ord(i)<=z : print(chr(a+(ord(i)-z+3)%26),end="") elif A<=ord(i)<=Z: print(chr(A + (ord(i) - Z + 3) % 26), end="") else: print(i,end="")
网址观察与批量生成
for i in range(2,254): url=‘http://news.gzcc.cn/html/xiaoyuanxinwen/{}.html‘.format(i) print(url)
2.英文词频统计预处理
story=‘‘‘
‘"Mr.Johnson had never been up in an aerophane before and he had read a lot about air accidents, so one day when a friend offered to take him for a ride in his own small phane, Mr.Johnson was very worried about accepting. Finally, however, his friend persuaded him that it was very safe, and Mr.Johnson boarded the plane.
His friend started the engine and began to taxi onto the runway of the airport. Mr.Johnson had heard that the most dangerous part of a flight were the take-off and the landing, so he was extremely frightened and closed his eyes.
After a minute or two he opened them again, looked out of the window of the plane, and said to his friend, "Look at those people down there. They look as small as ants, don‘t they?"
"Those are ants," answered his friend. "We‘re still on the ground.""
‘‘‘
story=story.lower()
print(story)
story=story.replace(‘?‘,‘ ‘).replace(‘,‘,‘ ‘).replace(‘.‘,‘ ‘).replace(‘!‘,‘ ‘)
print(story)
story=story.split(‘ ‘)
print(story)
str=input("输入要统计的单词:")
count=story.count(str)
print(count)
以上是关于字符串操作,英文词频统计预处理的主要内容,如果未能解决你的问题,请参考以下文章