组合数据类型,英文词频统计

组合数据类型

mystr='https://edu.cnblogs.com/campus/gzcc/14NetworkEngineering/homework/870'
ls=mystr.split('/')
print(mystr,ls)

classmates = ['Michael', 'Bob', 'Tracy','李三' ,'Tracy',56]
print(classmates.count('Tracy'))
classmates.insert(1,'Jack')
classmates.append('Rose')
#classmates.extend(ls)
#classmates.sort(classmates)
print(classmates)
classmates.pop(1)
print(classmates)

ls=list(range(0,50,5))
lsser=list('Michael')
print(ls,lsser)

classmatesTu=tuple(classmates)
print(classmates)
print(classmatesTu)

  

英语词频统计

perfectstr='''I found a love for me
Darling just dive right in and follow my lead
Well I found a girl beautiful and sweet
I never knew you were the someone waiting for me
Cause we were just kids when we fell in love
Not knowing what it was I will not give you up this time
But darling just kiss me slow your heart is all I own
And in your eyes you're holding mine
Baby I'm dancing in the dark with you between my arms
Barefoot on the grass listening to our favourite song
When you said you looked a mess I whispered underneath my breath
But you heard it darling you look perfect tonight
Well I found a woman stronger than anyone I know
She shares my dreams I hope that someday I'll share her home
I found a love to carry more than just my secrets
To carry love to carry children of our own
We are still kids but we're so in love fighting against all odds
I know we'll be alright this time
Darling just hold my hand be my girl I'll be your man
I see my future in your eyes
Baby I'm dancing in the dark with you between my arms
Barefoot on the grass listening to our favourite song
When I saw you in that dress looking so beautiful
I don't deserve this darling you look perfect tonight
Baby I'm dancing in the dark with you between my arms
Barefoot on the grass listening to our favourite song
I have faith in what I see
Now I know I have met an angel in person
And she looks perfect I don't deserve this
You look perfect tonight'''
#将标点符号,特殊符号转换为空格
perfectstr=perfectstr.replace(',','')
perfectstr=perfectstr.replace('''''','')
perfectstr=perfectstr.replace(':','')
perfectstr=perfectstr.replace('.','')
perfectstr=perfectstr.replace('?','')
perfectstr=perfectstr.replace('!','')
perfectstr=perfectstr.replace('\n','')
#去掉空格
perfectstr=perfectstr.lstrip()
print(perfectstr)
#将全部变成小写化
a=perfectstr.lower()
print(a)
#将每个单词分隔
perfectstrList=perfectstr.split()
print(len(perfectstrList),perfectstrList)
#用set把字符串转换成集合
strSet=set(perfectstrList)
print(strSet)
#计算单词出现的次数
strDict={}
for hello in strSet:
    strDict[hello] =perfectstr.count(hello)
print(strDict,len(strDict))

  

 

转载于:https://www.cnblogs.com/ljy28/p/9753373.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值