英文词频统计预备,组合数据类型练习

1.

s='''His palms are sweaty, knees weak, arms are heavy
There's vomit on his sweater already, mom's spaghetti
He's nervous, but on the surface he looks calm and ready
To drop bombs, but he keeps on forgettin
What he wrote down, the whole crowd goes so loud
He opens his mouth, but the words won't come out
He's chokin, how everybody's jokin now
The clock's run out, time's up over, bloah!
Snap back to reality, Oh there goes gravity
Oh, there goes Rabbit, he choked
He's so mad, but he won't give up that
Is he? No
He won't have it , he knows his whole back city's ropes
It don't matter, he's dope
He knows that, but he's broke
He's so stacked that he knows
When he goes back to his mobile home, that's when it's
Back to the lab again yo'''

s=s.replace(',',' ')
s=s.replace('!',' ')  
s=s.replace('?',' ')   #将所有,.?!等替换为空格
s=s.lower()              #所有大写转换为小写
print('he出现的次数:',s.count('he'))
b=s.split(' ')
print(b)

 

2.

a=list('123321132213')
 
a.append('3') #增加
print(a)
a.pop(1) #删除
print(a)
a.index('3') #查询
print(a)
a.insert(2,'3') #更改
print(a)
print(a.count('2'))

 

3。

异:元组是(1,2,3)这种格式,他是不可变的,你不能对它添加或者删除元素。

       而列表是可变的,格式是[1,2,3],你可以对它进行修改。

同:列表与元组都是容器,是一系列的对象,列表和元组都属于有序序列。

posted @ 2017-09-22 19:03  017黄乐仪  阅读(123)  评论(0编辑  收藏  举报