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

组合数据类型练习,英文词频统计实例上

时间:2017-09-26 13:10:08      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:logs   alt   scores   cores   image   err   key   数据   lin   

1.

>>> dic={}>>> dic[01]=59
>>> dic[02]=59.1
>>> dic[03]=59.2
>>> dic[04]=59.3
>>> dic[05]=60
>>> dic
{01: 59, 02: 59.1, 03: 59.2, 04: 59.3, 05: 60}
>>> dic[06]=59.5
>>> dic
{01: 59, 02: 59.1, 03: 59.2, 04: 59.3, 05: 60, 06: 59.5}
>>> dic.pop(01)
59
>>> dic[02]=61
>>> dic
{02: 61, 03: 59.2, 04: 59.3, 05: 60, 06: 59.5}
>>> dic.get(06)
59.5
>>> dic.keys()
dict_keys([02, 03, 04, 05, 06])
>>> dic.values()
dict_values([61, 59.2, 59.3, 60, 59.5])

2.

>>> names=[Rose,Wade,Paul,James,Kobe]
>>> scores=[1,3,13,23,24]
>>> ns=dict(zip(names,scores))
>>> ns
{Rose: 1, Wade: 3, Paul: 13, James: 23, Kobe: 24}
>>> s=set(names)
>>> s
{Kobe, Rose, Paul, Wade, James}
>>> s.add(Bosh)
>>> s
{Kobe, Rose, Paul, Wade, James, Bosh}
>>> s.remove(Bosh)
>>> s
{Kobe, Rose, Paul, Wade, James}
>>> ss=set(323211123321)
>>> ss
{3, 2, 1}
>>> sss=s|ss
>>> sss
{Kobe, 1, 2, Wade, James, 3, Rose, Paul}
>>> s&ss
set()
>>> sss-s
{1, 2, 3}
>>> ls=list(321321321321321321)
>>> ls
[3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1]
>>> tu.tuple(3213211321)
Traceback (most recent call last):
  File "<pyshell#37>", line 1, in <module>
    tu.tuple(3213211321)
NameError: name tu is not defined
>>> tu=tuple(3212113)
>>> tu
(3, 2, 1, 2, 1, 1, 3)
>>> se=set(32112133)
>>> se
{3, 2, 1}
>>> 
>>> for i in ls:
    print(i)

    
3
2
1
3
2
1
3
2
1
3
2
1
3
2
1
3
2
1
>>> for i in ns:
    print(i)

    
Rose
Wade
Paul
James
Kobe
>>> for i in ns:
    print(i,ns[i])

    
Rose 1
Wade 3
Paul 13
James 23
Kobe 24

 

技术分享

技术分享

 

组合数据类型练习,英文词频统计实例上

标签:logs   alt   scores   cores   image   err   key   数据   lin   

原文地址:http://www.cnblogs.com/blackboardf/p/7595964.html

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