首页 > 其他 > 详细

第三周作业

时间:2018-09-21 22:31:57      阅读:165      评论:0      收藏:0      [点我收藏+]
##列表遍历
classmates = [Michael,Bob,Jack,Tracy,Tom,Lucy]
print(classmates)
classmatesList = classmates    #列表的遍历
for word  in classmatesList:
    print(word)

技术分享图片

##元组遍历
classmatesT = (1,3,2,6,5,7)
sTuple = tuple(classmatesT)
for numb in sTuple:
    print(numb)

技术分享图片
##字典遍历
sDict = {name1:Michael,name2:Jack,name3:Tom}
for key in sDict:
    print(key,value:,sDict[key])


技术分享图片

##集合遍历
classmatesS = ([Michael,Bob,Jack,Tracy,Tom,Lucy])
sSet = set(classmatesS)
for name in sSet:
    print(name)

技术分享图片
##英文词频统计
str = ‘‘‘im a big big girl 
in a big big world 
its not a big big thing if you leave me 
but i do do feel 
that i too too will miss you much 
miss you much... 

i can see the first leaf falling 
its all yellow and nice 
its so very cold outside 
like the way im feeling inside 
im a big big girl 
in a big big world 
its not a big big thing if you leave me 
but i do do feel 
that i too too will miss you much 
miss you much... 

im a big big girl 
in a big big world 
its not a big big thing if you leave me 
but i do do feel 
that i too too will miss you much 
miss you much... 

im a big big girl 
in a big big world 
its not a big big thing if you leave me 
but i do do feel 
that i too too will miss you much 
miss you much... 

 ‘‘‘    #下载一首英文歌词
strList = str.split() #分隔一个一个单词list
print(strList)
strDicr = { }    ##统计每个单词出现的次数dict
for word in strList:
    strDicr[word] = strList.count(word)
    print(strDicr)

技术分享图片

列表,元组,字典,集合的联系与区别:

列表:[ ]可以进行的操作包括索引,切片,加,乘,检查成员,列表的数据项不需要具有相同的类型,因为列表有增删改的作用,所以速度会比元组快。

元组:()是存一组数据,只要一旦创建,便不能修改,所以又叫只读列表。只需要在括号中添加元素,并使用逗号隔开即可。

字典:{key,value}是另一种可变容器模型,且可存储任意类型对象。字典的每个键值对()用冒号(:)分割每个对之间用逗号(,)分割,整个字典包括在花括号({})中

集合 : ()是一个无序的,不可重复的,数据组合,可以去掉重复值,还可以进行关系测试

 

第三周作业

原文:https://www.cnblogs.com/XLxielin/p/9688619.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!