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

本文深入探讨了Python中四种主要的数据结构:列表、元组、字典和集合的特点及使用方法。通过实例展示了每种数据结构的基本操作,为读者提供了直观的理解。

列表:用list()函数或者[]创建,是可变序列。
元组:用()或者tuple()函数来实现;是不可变序列。
字典:用dict()函数或者{}创建,使用键-值(key-value)存储,键是不可变的对象。
集合:用set()函数或者{}创建,是一个无序不重复元素集。

#列表
list=['Tt','Aa','Bb',10]
print(list)
for A1 in list:
    print(A1)
#元组
Tuple1=('abcdefg')
print(Tuple1)
for B1 in Tuple1:
    print(B1)
#集合
Set1={2,4,6,8}
print(Set1)
for c in Set1:
    print(c)
#字典
dict1 = {'a':55,'b':66,'c':77}
print(dict1)
for d in dict1:
    print(d,dict1[d])

  

hh='''You're on the phone with your girlfriend
She's upset
She's going off about something that you said
'Cause she doesn't get your humor like I do
I'm in my room
It's a typical Tuesday night
I'm listening to the kind of music she doesn't like
And she'll never know your story like I do
But she wears short skirts
I wear T-shirts
She's cheer captain
And I'm on the bleachers
Dreaming about the day when you wake up
And find that what you're looking for has been here the whole time
If you can see I'm the one who understands you
Been here all along so why can't you see
You belong with me
You belong with me
Walkin' the streets with you and your worn-out jeans
I can't help thinking this is how it ought to be
Laughing on a park bench thinking to myself
Hey isn't this easy
And you've got a smile that could light up this whole town
I haven't seen it in a while since she brought you down
You say you're fine
I know you better then that
Hey what you doing with a girl like that
She wears high heels
I wear sneakers
She's cheer captain and I'm on the bleachers
Dreaming about the day when you wake up
And find that what what you're looking for has been here the whole time
If you can see that I'm the one who understands you
Been here all along so why can't you see
You belong with me
Standing by and waiting at your back door
All this time how could you not know
Baby you belong with me
You belong with me
Oh I remember you drivin' to my house in the middle of the night
I'm the one who makes you laugh
When you know you're about to cry
And I know your favorite songs
And you tell me about your dreams
I think I know where you belong
I think I know it's with me
Can't you see that I'm the one who understands you
Been here all along so why can't you see
You belong with me
Standing by and waiting at your back door
All this time
How could you not know
Baby you belong with me
You belong with me
You belong with me
Have you ever thought just maybe
You belong with me
You belong with me'''.lower()
aa = ''',."?!'''
for word in aa:
    str2 =hh.replace('word',' ')
hh =hh.replace('\n','')
hh = hh.strip()
hh = hh.split(' ')
print(hh)

strSet=set(hh)
for word in strSet:
   print(word,hh.count(word))
dict={}          #单词计数字典
for word in hh:
  dict[word] = hh.count(word)
print(len(dict),dict)

  

 

转载于:https://www.cnblogs.com/SpaldingWen/p/9765267.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值