标签:insert 英文 print 数据 使用 color end been 转换
1.实例: 下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词。
str=‘‘‘We don‘t talk anymore We don‘t talk anymore We don‘t talk anymore Like we used to do We don‘t laugh anymore What was all of it for? We don‘t talk anymore Like we used to do I just heard you found the one you‘ve been lookin‘ The one you been looking for I wish i would‘ve konwn that wasn‘t me Cause even after all this time i still wonder Why i can‘t move on? Just the way you dance so easliy Don‘t wanna know The kinda dress you‘re wearin‘ tonight If he‘s holdin‘ onto you so tight The way i did before I overdosed Should‘ve known your love was game Now I can‘t get‘cha out of my brain Ooh it‘s such a shame We don‘t talk anymore We don‘t talk anymore We don‘t talk anymore Like we used to do We don‘t laugh anymore What was all of it for? We don‘t talk anymore Like we used to do I just hope you‘r lyin‘ next to somebody Know it‘s hard to love ya like me Must be a good reason that you‘re gone Every now and then I think you might want me to come show up your door But I‘m just too afraid that i‘ll be worng Don‘t wanna know If you‘ra lookin‘ into her eyes If she‘s holdin‘ onto you so tight The way i did before I overdosed Should‘ve know your love was a game Now I can‘t get‘cha out of my brain Ooh it‘s such a shame We don‘t talk anymore We don‘t talk anymore We don‘t talk anymore Like we used to do We don‘t laugh anymore What was all of it for? We don‘t talk anymore Like we used to do Like we used to do Don‘t wanna know The kinda dress you‘re wearin‘ tonight If he‘s givin‘ it to you just right The way i did before I overdosed Should‘ve know your love was a game Now I can‘t get‘cha out of my brain Ooh it‘s such a shame ‘‘‘ for i in ",.?!\n": str=str.replace(i," ") str=str.lower() str=str.split(" ") words=set(str) dt={} dt["we"]=str.count("we") dt["talk"]=str.count("talk") for i in words: dt[i]=str.count(i) for i in dt: print("{0:<10}{1}".format(i,dt[i]))
2.列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。
f=list(‘221211322313212222132‘) f.append(‘2‘) //添加 f.pop(0) //删除 f.insert(3,‘3‘) // 插入 list(range(5)) //遍历 f.index(‘3‘) //第一个3分下标 f.count(‘1‘) //1分同学的个数 f.count(‘3‘) //3分中学的个数
3.简要描述列表与元组的异同。
列表是一种有序的序列,正向递增、反向递减序号,可以随时添加和删除其中的元素。没有长度限制、元素类型可以不同。
元组与列表类似,不同之处在于元组的元素不能修改。元组使用小括号,列表使用方括号。
标签:insert 英文 print 数据 使用 color end been 转换
原文地址:http://www.cnblogs.com/yangjlee/p/7574109.html