组合数据类型练习,英文词频统计实例上列表,元组,字典,集合的遍历。 总结列表,元组,字典,集合的联系与区别。

1.字典实例:建立学生学号成绩字典,做增删改查遍历操作。

d={‘天‘:95,‘青‘:78,‘色‘:65,‘等‘:66}
print(‘学生成绩字典:‘,d)
d[‘烟‘]=98
print(‘增加:‘,d)
d.pop(‘等‘)
print(‘删除:‘,d)
d[‘天‘]=78
print(‘修改:‘,d)
print(‘查询青成绩:‘,d.get(‘青‘,‘无‘))

2.列表,元组,字典,集合的遍历。
总结列表,元组,字典,集合的联系与区别。

s=list(‘123456789‘)
t=set(‘756423189‘)
c={‘炊烟‘:‘1‘,‘袅袅‘:‘3‘,‘升起‘:‘2‘}
x=(1, 2, 3, 4, 5 )
print(‘列表的遍历为:‘,end=‘‘)
for i in s:
print(i,end=‘‘)
print()
print(‘元祖的遍历为:‘,end=‘‘)
for i in x:
print(i,end=‘‘)
print()
print(‘字典key的遍历为:‘,end=‘‘)
for i in c:
print(i,end=‘‘)
print()
print(‘字典value的遍历为:‘,end=‘‘)
for i in c.values():
print(i,end=‘‘)
print()
print(‘数组的遍历为:‘,end=‘‘)
for i in x:
print(i,end=‘‘)

3. 英文词频统计实例

A.待分析字符串

B.分解提取单词

大小写 txt.lower()

分隔符‘.,:;?!-_’

单词列表

C.单词计数字典

news=‘‘‘I said excuse me little mama if I may,
Take this thought and send it your way,
And if you don‘t like that,
then send it right back,
But I just gotta say
I wanna be on you (on you),
I wanna be on you (on you)
And if you don‘t like that,
then send it right back
But I just gotta say,
I just gotta say
Hey, sh sh shawty with no limits,
that‘s what I need all the time,
I‘m wit with with it, she with it,
she not sure she put it down
Come get get get it, the business,
I hi hit it, whose is it
The Benz with the windows tinted,
oh I get dirty south
Showning, like them grown men,
goose patrongen
Let let me go in, sexy moanin,
ca catch me jonesin
Let no not ever with
this little mama off schedule
Got me achy, call me papi,
hottest I be fly as feathers
But but bout that, sh shawty housed that,
you you got that prowl cat
I wanna pop it like ecstasy,
pretty face and all thatbillion yuan (2.1 billion U.S. dollars) year on year in the first fiscal3 quarter ending June. The group‘s revenue was about 50 billion yuan in the quarter, up 56 percent year on year.‘‘‘
news=news.lower()
for i in ‘,.()‘:
news=news.replace(i,‘ ‘)
words=news.split(‘ ‘)
print(words)

 

时间: 2024-08-04 13:58:23

组合数据类型练习,英文词频统计实例上列表,元组,字典,集合的遍历。 总结列表,元组,字典,集合的联系与区别。的相关文章

组合数据类型和英文词频统计实例

1.列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作.例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等. >>> ls=list('1231323232323131323') >>> ls ['1', '2', '3', '1', '3', '2', '3', '2', '3', '2', '3', '2', '3', '1', '3', '1', '3', '2', '3'] >>> ls.append('4'

组合数据类型练习,英文词频统计实例上

字典实例:建立学生学号成绩字典,做增删改查遍历操作. #创建一个空字典 dict={} s=dict print(s) #增加键值对(学号-成绩) s['001']=60 s['002']=70 s['003']=80 s['004']=90 print(s) #删除 s.pop('004') print(s) #修改 s['001']=69 print(s) #查找键是否存在 s.get('005','不存在') print(s) #便历 for i in s: print(i) 2.列表,元

八、组合数据类型练习,英文词频统计实例上

1.字典实例:建立学生学号成绩字典,做增删改查遍历操作. dict={'001':'66','003':'77','006':'88','009':'99'} print('学生学号成绩:',dict) dict['007']=96 print('增加学号为007的学生的成绩为96:',dict) dict.pop('001') print('删除学号为001的学生的记录:',dict) dict['007']=100 print('修改学号为007的学生的成绩为100:',dict) prin

作业8-组合数据类型练习,英文词频统计实例上

1.字典实例:建立学生学号成绩字典,做增删改查遍历操作. 总结列表,元组,字典,集合的联系与区别. 运行结果: 2.列表,元组,字典,集合的遍历,总结列表,元组,字典,集合的联系与区别. 运行结果: 区别: 列表用"[]"表示,列表是可变的数据类型,即这种类型是可以被改变的,并且列表是可以嵌套的. 元组用"()"表示,元祖和列表十分相似,不过元组是不可变的,但也可以嵌套. 字典用"{}"表示,注意它们的键/值对用冒号分割,而各个对用逗号分割,所有

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

练习: 总结列表,元组,字典,集合的联系与区别.列表,元组,字典,集合的遍历. 区别: 一.列表:列表给大家的印象是索引,有了索引就是有序,想要存储有序的项目,用列表是再好不过的选择了.在python中的列表很好区分,遇到中括号(即[ ]),都是列表,定义列表也是如此.列表中的数据可以进行增删查改等操作: 增加有两种表达方式(append().expend()),关于append的用法如下(注:mylist定义的列表名称):不难看出,用append方法增加元素,不用给元素加中括号,而用exten

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

列表,元组,字典,集合的联系与区别:1,列表的增删改查的时间消耗随着元素的增加而增加,当元素大的时候比较浪费时间3.元组只能查,不能增删改,可以保证数据的安全性,因为可操作性较低,资源占用也较少,适合用来存储经常查但不经常修改的数据4.集合最重要的一个特性就是去重,适合用于存储不重复的key 5.列表元组集合都可以以进行数据的增删改查6.字典存放的数据是key:value类型的,通过key可以非常快速的查找到对应的value.但是占用的内存和空间较大,是一种空间换时间的数据类型 英文歌词: st

组合数据类型练习,英文词频统计实例

1.由字符串创建一个作业评分表,做增删改查询统计遍历操作,例如查询第一个3分的下标,统计1分的同学有几个,3分的同学有几个,增删改查等等. 2.字典实例:建立学生学号成绩字典,做增删改查遍历操作. 3.列表,元组,字典,集合的遍历. 4.英文词频统计实例 news = '''When I was young I'd listen to the radio Waiting for my favorite songs When they played I'd sing along, It make

组合数据练习,英语词频统计实例上

1 >>> d={'01':95,'02':92,'03':86,'04':70}>>> print(d){'01': 95, '02': 92, '03': 86, '04': 70}>>> d['05']=80>>> print(d){'01': 95, '02': 92, '03': 86, '04': 70, '05': 80}>>> d.pop('02')92>>> print(d){'0

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

1.列表,元组,字典,集合分别如何增删改查及遍历. 列表:list1 = ["a", "b", "c", "d"]; #设置列表1 print(list1); #输出列表1 #增list1.insert(4,'e'); #增添元素print(list1); #删list1.pop(3) #删除指定位置元素print(list1); #改list1[0] = 'q' #直接修改位置元素print(list1) #查x = lis