英文词频统计预备,组合数据类型练习
实例: 下载一首英文的歌词或文章,将所有,.?!替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词。
troye='''We are runnin' so fast And we never look back And whatever I lack you make up We make a really good team And though not everyone sees We got this crazy chemistry Between us Jump starting your car cause this city's a bore Buying e-cigarettes at the convenience store Making new cliches on our own little tour Let's ride You don't have to say I love you to say I love you Forget all the shooting stars and all the silver moons We've been making shades of purple out of red and blue Sickeningly sweet like honey don't need money All I need is you Hey All I need is you you We try staying up late But we both are light weights Yeah we get off our face too easy And we take jokes way too far And sometimes living's too hard We're like two halves of one heart You don't have to say I love you to say I love you Forget all the shooting stars and all the silver moons We've been making shades of purple out of red and blue (Singing with me) We sickeningly sweet like honey don't need money All I need is you All I need is you you We are not a commercial for anyone else We go out for coffee and keep it to ourselves We make little homes of three stars hotels And i know what's your feeling cause I feel it as well Hey You don't have to say I love you to say I love you Forget all the shooting stars and all the silver moons Cause we've been making shades of purple out of red and blue Hey We sickeningly sweet like honey don't need money All I need is you Hey All I need is you you You All I need is you you say I love you to say I love you Forget all the shooting stars and all the silver moons We've been making shades of purple out of red and blue We sickeningly sweet like honey don't need money All I need is you All I need is you you Thank you guys,thank you so much''' troye=troye.lower() for i in ',': troye=troye.replace(i,' ') print(troye.count('you')) troyes=troye.split(' ') print(troyes)
实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。
全部改为数值型
查询第一个3分的下标
1分的同学有多少个,3分的同学有多少个
grade=list('23654321') print('初始:',grade) grade.append('8') print('增‘8’:',grade) grade.insert(1,'1') print('插1:',grade) grade.pop() print('删:',grade) grade[2]='4' print('改:',grade) print('第一个3的下标是:',grade.index('3')) print('1分的同学有:',grade.count('1')) print('3分的同学有:',grade.count('3')) for i in range(len(grade)): grade[i]=int(grade[i]) print(grade)
简要描述列表与元组的异同。
元组一旦初始化就不能改变里面的元素,而列表可以。
列表中的项目应该包括在方括号中,元组在圆括号中
你可以增删改或是搜索列表中的项目。
知识点:
全部大写:str.upper()
全部小写:str.lower()
首字母大写其余小写:str.capitalize()
首字母大写:str.title()
大小写互换:str.swapcase()
print('constellation'.center(46,'-’))
print('开始执行'.center(50,'-'))
print(big.count('big’))
print(big.replace(‘girl’,’boy’))
'https://edu.cnblogs.com/campus/gzcc/14NetworkEngineering/homework/870'.split('/’)
'201406114412'.lstrip(‘20’)
'aaaaaaaaababaaaa'.strip('a')
'aaaaaaaaababaaaa'.rstr
classmates = [‘Michael’, ‘Bob’, ‘Tracy’,‘李三’ ,‘Tracy’,56]
classmates[1],classmates[-1]
classmates[1] = 'Sarah'
len(classmates),max(classmates), min(classmates)
classmates.sort()
classmates.count(‘Tracy’), classmates.index(‘Tracy’)
classmates.append('Adam’)
classmates.insert(1, 'Jack’)
classmates.pop()
classmates.pop(1)
list(range(5)),list(‘turtle’)