zoukankan      html  css  js  c++  java
  • lists and Dictionaries

    >>> print {i : chr(65+i) for i in range(4)}
        {0 : 'A', 1 : 'B', 2 : 'C', 3 : 'D'}
    
        >>> print {k : v for k, v in someDict.iteritems()} == someDict.copy()
        1
    
        >>> print {x.lower() : 1 for x in list_of_email_addrs}
        {'barry@zope.com'   : 1, 'barry@python.org' : 1, 'guido@python.org' : 1}
    
        >>> def invert(d):
        ...     return {v : k for k, v in d.iteritems()}
        ...
        >>> d = {0 : 'A', 1 : 'B', 2 : 'C', 3 : 'D'}
        >>> print invert(d)
        {'A' : 0, 'B' : 1, 'C' : 2, 'D' : 3}
    
        >>> {(k, v): k+v for k in range(4) for v in range(4)}
        ... {(3, 3): 6, (3, 2): 5, (3, 1): 4, (0, 1): 1, (2, 1): 3,
             (0, 2): 2, (3, 0): 3, (0, 3): 3, (1, 1): 2, (1, 0): 1,
             (0, 0): 0, (1, 2): 3, (2, 0): 2, (1, 3): 4, (2, 2): 4, (
             2, 3): 5}
    

      

  • 相关阅读:
    数据结构 1
    MyBatis 7
    MyBatis 6
    MyBatis 5
    MaBatis 4
    MyBatis 3
    目录和文件管理
    Linux常用命令精讲
    Sentos7.4安装说明
    RIP
  • 原文地址:https://www.cnblogs.com/wangwenfei/p/python.html
Copyright © 2011-2022 走看看