Python-3-数据结构(字典)

1 字典

特点

1.键-值成对出现 “键:值 ”

2.键不能重复

3.键不可更改,值可以修改

4.键来索引值

5.键只能是不可变的数据类型

dic_Python={
    'the define':1,
    'the age':2,
    'the clude':['A','B']
}
#增删查改
dic_Python['the age']
dic_Python['the define']=77#赋值修改
dic_Python['hello']=50#赋值添加键值对
dic_Python.update({'hi':'world',})

del dic_Python['the age']#删除指定键值对

dic_Python.keys()#访问字典所有键
dic_Python.values()#访问字典所有值
dic_Python.items()#访问字典所有键值对

third_dic={i:i**3 for i in range(1,11)}




2 统计单词词频

常用方法

1.字符串.lower()#将所有字母转为小写形式

2.字符串.split()#将字符串拆分 返回列表,包含一系列单词

 

sentence_1='Many flowers and trees have withered this night;Death will soon come and plant them over again.'
sentence_1.lower()
words=sentence_1.split()
word_num={}
for word in words:
    if word in word_num:
        word_num[word]+=1
    else:
        word_num[word]=1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值