1.英文词频统计:
strBig = ('''Big Big World
Emilia
I'm a big big girl
In a big big world
It's 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
It's all yellow and nice
It's so very cold outside
Like the way I'm feeling inside
I'm a big big girl
In a big big world
It's 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.
Outside it's now raining
And tears are falling from my eyes
Why did it have to happen
Why did it all have to end
I'm a big big girl
In a big big world
It's 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 have your arms around me ooooh like fire
But when I open my eyes
You're gone.
I'm a big big girl
In a big big world
It's 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'm a big big girl
In a big big world
It's not a big big thing if you leave me
But I do feel that will miss you much
Miss you much.''')
strList = strBig.split()
print(len(strList),strList)
print(strBig.lower())#将所有大写转换为小写
strSet = set(strList)
print(len(strSet),strSet)
strDict = {}
for word in strSet:
strDict[word] = strList.count(word)
print(strDict.items())
print(len(strDict),strDict)
print(strDict['big'])
print(len(strDict),strDict)
strListSort = strList.sort()
print(strListSort)
print(strList)
for word in strList:
print(word,strList.count(word))
运行结果:
2.列表,元组,字典,集合的遍历
classmates = ['Michael','Bob','Tracy','李三','Tracy',56]
new = ['Rose','Jack']
classmates.insert(2,'Tom')#插入
classmates.append('Jack')#追加
classmates.extend(new)#扩展
classmates.pop(-1)#
print(classmates)
classmatesSet = set(classmates)
classmatesSet.add('Jack')
classmatesSet.remove('Bob')
print(classmatesSet)
print(list('abcdef'),tuple('abcdef'))
classmates = ['Tracy','Bob','Tracy','李三','Tracy',56]
score = [85,90,50,60]
cs = dict(zip(classmates,score))
print(cs)
s = {1,2,3}
s.add(4)#增加
print(s)
s.remove(4)#删除
print(s)
s = set([1, 1, 2, 2, 3, 3])#生成
print(s)
#集合运算
s1 = set([1, 2, 3])
s2 = set([2, 3, 4])
print(s2-s1)
运行结果: