字典实例:建立学生学号成绩字典,做增删改查遍历操作。
d={'01':'80','02':'70','03':'76','04':'86','05':'82'}
print(d.keys())print(d.values())d['08']=98d['03']=99d.pop('02')print(d.get('07'))print(d)列表,元组,字典,集合的遍历。
总结列表,元组,字典,集合的联系与区别。str=list('123112312')
tu=tuple('abcdrfghj')s=set([5,4,3,1,6])d=dict(zip(tu,str))print(str)print(tu)print(s)print(d)for i in str: print(i)for j in tu: print(j)for h in s: print(h)for k in d: print(k,d[k])
英文词频统计实例
待分析字符串
分解提取单词
大小写 txt.lower()
分隔符'.,:;?!-_’
单词列表
单词计数字典
new='''After the Winter - Lenka
When the rain is pourin' down
"And there are snowflakes on your cheeks"
When your heart is frozen over
And there is a sea lost sun in weeks
Just remember,
Just remember,
After the winter comes the spring
That is when the blue birds
Starts to sing
And you can always count on this
After the winter comes the spring
When the trees have lost the color
And the sky is full of fears
When you feel you are going under
And your eyes are full of tears
When the bells are all hiding
And you are hiding too
Oh, darling just remember
That everything will soon be new
After the winter comes the spring
That is when the blue birds
Start to use their wings
And you can always count on this
After the winter comes the spring
Just remember,
Just remember,
Just remember,
Just remember,
After the winter comes the spring.
That is when the blue birds.
Starts to sing.
And you can always count on this
After the winter comes the spring
After the winter comes the spring'''
new = new.lower()
for i in ',."': new = new.replace(i,' ')new = new.split(' ')words = set(new)d = {}for i in words: d[i] = new.count(i)for i in d:
print('{0:<15}{1}'.format(i,d[i]))