• 学习心得2020.08.01


    025 字典

    创建和访问字典

    >>> brand=['李宁','耐克','阿迪','鱼C']
    >>> slogan=['一切皆有可能','Just do it','Impossible is nothing','让编程改变世界']
    >>> print('鱼C工作室的口号是:',slogan[brand.index('鱼C')])
    鱼C工作室的口号是: 让编程改变世界
    >>> dict1={'李宁':'一切皆有可能','耐克':'Just do it','阿迪':'Impossible is nothing','鱼C':'让编程改变世界'}
    >>> print('鱼C工作室的口号是:',dict1['鱼C'])
    鱼C工作室的口号是: 让编程改变世界
    >>> dict2={1:'one',2:'two',3:'three'}
    >>> dict2
    {1: 'one', 2: 'two', 3: 'three'}
    >>> dict2[2]
    'two'
    

    026 字典

    fromkeys()创建和访问一个新的函数

    >>> dict1={}
    >>> dict1.fromkeys((1,2,3))
    {1: None, 2: None, 3: None}>>> dict1.fromkeys((1,2,3),'Number')
    {1: 'Number', 2: 'Number', 3: 'Number'}
    >>> dict1.fromkeys((1,2,3),('one','two','three'))
    {1: ('one', 'two', 'three'), 2: ('one', 'two', 'three'), 3: ('one', 'two', 'three')}
    >>> dict1.fromkeys((1,3),'girl')
    {1: 'girl', 3: 'girl'}>>> dict1=dict1.fromkeys(range(32),'赞')
    >>> dict1
    {0: '赞', 1: '赞', 2: '赞', 3: '赞', 4: '赞', 5: '赞', 6: '赞', 7: '赞', 8: '赞', 9: '赞', 10: '赞', 11: '赞', 12: '赞', 13: '赞', 14: '赞', 15: '赞', 16: '赞', 17: '赞', 18: '赞', 19: '赞', 20: '赞', 21: '赞', 22: '赞', 23: '赞', 24: '赞', 25: '赞', 26: '赞', 27: '赞', 28: '赞', 29: '赞', 30: '赞', 31: '赞'}
    >>> for eachKey in dict1.keys():
    	print(eachKey)
    
    	
    0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    >>> for eachValue in dict1.values():
    	print(eachValue)
    
    	
    赞
    赞
    赞
    赞
    赞
    赞
    赞
    赞
    赞
    赞
    赞
    赞
    赞
    赞
    赞
    赞
    赞
    赞
    赞
    赞
    赞
    赞
    赞
    赞
    赞
    赞
    赞
    赞
    赞
    赞
    赞
    赞
    
    
    
    
  • 相关阅读:
    word2vec的Java源码【转】
    将博客搬至CSDN
    去掉中英文符号
    搜索引擎原理和简单过程【转】
    写国际会议论文和期刊的一些注意事项
    Java中Map根据键值(key)或者值(value)进行排序实现
    solr 查询获取数量getCount()
    【solr filter 介绍--转】http://blog.csdn.net/jiangchao858/article/details/54989025
    将中文数字转为数字
    java.util.Properties类的介绍-配置文件的读写【-Z-】
  • 原文地址:https://www.cnblogs.com/rioca/p/13423605.html
Copyright © 2020-2023  润新知