博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
作业三
阅读量:6582 次
发布时间:2019-06-24

本文共 2930 字,大约阅读时间需要 9 分钟。

练习:

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

 

 

 列表,元组,字典,集合的遍历

#列表,元祖,字典,集合的遍历#列表list1 = [1,2,3,4,5]for i in list1:    print()#y元祖tuple = (10,23,65)for i in tuple:    print(i)#=集合set = {85,56,55,33,48,65}for i in set:    print(i)#字典
dict = {'金融':'1班','软件工程':'2班','信管':'3班'}for i in dict:     print(i,dict[i])

 

结果如下:

 

 

 

英文词频统计:

  • 下载一首英文的歌词或文章str
    str = '''HeyHavana ooh na naAyyHalf of my heart is in Havana ooh na naAyy ayyHe took me back to East Atlanta na na naAll of my heart is in HavanaAyyThere's somethin' 'bout his mannersUh huhHavana ooh na naHe didn't walk up with that how you doin'When he came in the roomHe said there's a lot of girls I can do withBut I can't without youI'm doin' forever in a minuteThat summer night in JuneAnd papa says he got malo in himHe got me feelin' likeOooh oooh ooh I knew it when I met himI loved him when I left himGot me feelin' likeOooh oooh ooh and then I had to tell himI had to go oh na na na na naHavana ooh na naAyyHalf of my heart is in Havana ooh na naAyy ayyHe took me back to East Atlanta na na naAll of my heart is in HavanaAyyMy heart is in HavanaHavana ooh na naJefferyJust graduated fresh on campus mmmFresh out East Atlanta with no manners damnFresh out East AtlantaBump on her bumper like a traffic jamJamHey I was quick to pay that girl like uncle SamHere you go ayyBack it on me shawty cravin' on meGet to diggin' on meOn meShe waited on meThen whatShawty cakin' on me got the bacon on meWait upThis is history in the makin' on meOn mePoint blank close range that beIf it cost a million that's meThat's meI was gettin' mula man they feel meHavana ooh na naAyy ayyHalf of my heart is in Havana ooh na naOh ayy ayyHe took me back to East Atlanta na na naOh noAll of my heart is in HavanaAyyMy heart is in HavanaAyyHavana ooh na naOoh na na oh na na naTake me back back back likeOoh na na oh na na naTake me back back back likeOoh na na oh na na naTake me back back back likeOoh na na oh na na naTake me back back backYeah ayyOooh oooh oohOooh oooh oohTake me back to my HavanaHavana ooh na naHalf of my heart is in Havana ooh na naOh yeahHe took me back to East Atlanta na na naAll of my heart is in HavanaMy heart is in HavanaAyyHavana ooh na naUh huhOh na na naOh na na naHeyOh na na naNo no no take me backOh na na na'''strCount = str.count('na')print(strCount)s1 = str.startswith('Hey')print('是否以start开头')print(s1)s2 = str.endswith('na')print('是否以na结尾:')print(s2)s3 = str.isspace()print('是否为空')print(s3)s4 = str.isalnum()print('是否全为字母或数字:')print(s4)s5 = str.isalpha('')print('是否全字母:')print(s5)s6 = str.isdigit()print('是否全为数字')print(s6)s7 = str.islower()print('是否全为小写')print(s7)s8 = str.isupper()print(s8)

    结果如下

  • 分隔出一个一个的单词 list
    #str每个单词分割组成列表形式str = ''''hanvana'''str = str.split()print(str)

     

  • 结果
  • #计算单词出现的次数 strList = ('adigugyqiegyiuagiwgre') print("计算单词出现的次数:") strSet=set(strList) for word in strSet:    print(word,strList.count(word))

     结果如下:

  •  

转载于:https://www.cnblogs.com/tangpaiq-/p/9688420.html

你可能感兴趣的文章
面试官:看你简历写了熟悉Kafka,它为什么速度会这么快?
查看>>
循环语句脚本
查看>>
SMTP错误码/建议解决方法
查看>>
bluestore设计的特点--2019_6
查看>>
我的友情链接
查看>>
linux中设置静态ip
查看>>
Android学习——HorizontalScollview水平滚动控件
查看>>
我的友情链接
查看>>
Python多线程ping检测机器存活(跨平台版)
查看>>
CIsco 3845 静态DNS条目(ip host)自动消失
查看>>
f2fs系列 之三:目录结构
查看>>
DBMS的工作模式
查看>>
aix文件系统在线扩容
查看>>
swoole教程第一节:进程管理模块(Process)-中(消息队列)
查看>>
java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
查看>>
有意思的文章的链接
查看>>
Entity Framework技术系列之6:数据绑定
查看>>
2019-05-13 Java学习日记之循环语句&方法
查看>>
MySQL 优化工具 MySQLTuner
查看>>
读取文件并替换内容
查看>>