码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-09-20 23:12:50      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:always   stay   嵌套   life   bsp   英文   ext   touch   int   

1、a=‘‘‘Every night in my dreams
I see you,I feel you
That is how I know you go on
Far across the distance
And spaces between us
You have come to show you go on
Near far
Wherever you are
I believe,
That the heart does go on
Once more you open the door
And you‘re here in my heart
And my heart will go on and on
Love can touch us one time
And last for a lifetime
And never let go till we‘re gone
Love was when I loved you,
One true time I hold to,
In my life well always go on
Near far,
Wherever you are,
I believe
That the heart does go on
Once more you open the door
And you‘re here in my heart
And my heart will go on and on
you‘re here,
There‘s nothing I fear
And I know,
That my heart will go on
Well stay forever this way
You are safe in my heart
And my heart will go on and on‘‘‘
a=a.replace(‘,‘,‘‘)
print(a)

b=a.lower()
print(b)
c=a.split(‘ ‘)
print(c)

统计my,heart,will,go的个数

print(‘my:{0}‘.format(a.count(‘my‘)))
print(‘heart:{0}‘.format(a.count(‘heart‘)))
print(‘will:{0}‘.format(a.count(‘will‘)))
print(‘go:{0}‘.format(a.count(‘go‘)))

2、a=list(‘1233212331‘)
for i in range(len(a)):
    a[i]=int(a[i])
    print(a)
#增加一个3分的
a.append (‘3‘)
print(a)
#删除最后一个
a.pop ()
print(a)
#修改第二个
a[1]=1
print(a)
#查询第三个
print(a[2])
#查询第一个3分的下标
for i in range(len(a)):
    if(a[i]==3):
        print(i)
        break
print (‘1分的同学有{0}个‘.format(a.count(1)))
print (‘3分的同学有{0}个‘.format(a.count(3)))

3、简要描述列表与元组的异同

答:元组和列表十分类似,但是元组不能被修改,列表可以被修改。

列表是处理一组有序项目的数据结构,即你可以在一个列表中存储一个序列的项目。

列表中的项目。列表中的项目应该包括在方括号中,因此可以增加或删除项目

列表是可以嵌套的。

元组通过圆括号中用逗号分隔的项目定义。

元组也是可以嵌套的。

 

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

标签:always   stay   嵌套   life   bsp   英文   ext   touch   int   

原文地址:http://www.cnblogs.com/154145kj/p/7565346.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!