第三次作业
一.列表,元组,字典,集合的遍历
#列表的遍历 List1=['Tracy',20,'Amy',10] print(List1) for a in List1: print(a) #元组的遍历 Tuple1=('你今天真好看') print(Tuple1) for b in Tuple1: print(b) #集合的遍历 Set1={1,2,3,4} print(Set1) for c in Set1: print(c) #字典的遍历 dict1 = {'a':80,'b':79,'c':90} print(dict1) for d in dict1: print(d,dict1[d])
运行结果
二.英文词频统计
str1='''It's a Beautiful Night We'Re Looking For Something Dumb To Do Hey Baby i Think i Wanna Marry You Is It The Look In Your Eyes Or Is It This Dancing Juice Who Cares Baby i Think i Wanna Marry You Well i Know This Little Chapel On The Boulevard We Can Go Whoa Whoa No One Will No Whoa Oh Come On Girl Who Cares If We'Re Trashed Got a Pocket Full Of Cash We Can Blow Whoa Whoa Shots Of Patrol Whoa Whoa And Guitar Girl Don't Say No No No No No Just Say Yeah Yeah Yeah Yeah Yeah And We'Ll Go Go Go Go Go If You'Re Ready Like i'm Ready Cos It's a Beautiful Nigt We'Re Looking For Something Dumb To Do Hey Baby i Think i Wanna Marry You Is It The Look In Your Eyes Or Is It This Dancing Juice Who Cares Baby i Think i Wanna Marry You Oh i'Ll Go Get The Ring Let The Choir Bell Sing Like Ooh Ooh Ooh So What You Wanna Do Ooh Ooh Lets Just Run Girl If We Wake Up And You Want To Break Up That's Cool Ooh Ooh No i Won't Blame You Ooh Ooh It Was Fun Girl Don't Say No No No No No Just Say Yeah Yeah Yeah Yeah Yeah And We'Ll Go Go Go Go Go If You'Re Ready Like i'm Ready Cos It's a Beautiful Night We'Re Looking For Something Dumb To Do Hey Baby i Think i Wanna Marry You Is It The Look In Your Eyes Or Is It This Dancing Juice Who Cares Baby i Think i Wanna Marry You Just Say i Do Ooh Ooh Ooh Tell Me Right Now Baby Tell Me Right Now Baby Baby Just Say i Do Ooh Ooh Ooh Tell Me Right Now Baby Tell Me Right Now Baby Baby Oh It's a Beautiful Night We'Re Looking For Something Dumb To Do Hey Baby i Think i Wanna Marry You Is It The Look In Your Eyes Or Is It This Dancing Juice Who Cares Baby i Think i Wanna Marry You''' #歌曲中去掉空格 str1=str1.lstrip() print(str1) #把单词全部变成小写 a=str1.lower() print(a) #将歌词的每个单词分隔 strList=str1.split() print(len(strList),strList) #用set把字符串转换成集合 strSet=set(strList) #计算每个单词出现的次数 for word in strSet: print(word,strList.count(word))
运行结果