• Python 字典(Dictionary) items()方法


    Python 字典(Dictionary) items() 函数以列表返回可遍历的(键, 值) 元组数组。

    Example #1:

     
    # Python program to show working
    # of items() method in Dictionary
      
    # Dictionary with three items 
    Dictionary1 = { 'A': 'Geeks', 'B': 4, 'C': 'Geeks' }
      
    print("Dictionary items:")
      
    # Printing all the items of the Dictionary
    print(Dictionary1.items())

    Output:

    Dictionary items:
    dict_items([('C', 'Geeks'), ('B', 4), ('A', 'Geeks')])

    Order of these items in the list may not always be same.
     
    Example #2: To show working of items() after modification of Dictionary.

    # Python program to show working
    # of items() method in Dictionary
      
    # Dictionary with three items 
    Dictionary1 = { 'A': 'Geeks', 'B': 4, 'C': 'Geeks' }
      
    print("Original Dictionary items:")
      
    items = Dictionary1.items()
      
    # Printing all the items of the Dictionary
    print(items)
      
    # Delete an item from dictionary
    del[Dictionary1['C']]
    print('Updated Dictionary:')
    print(items)

    Output:

    Original Dictionary items:
    dict_items([('A', 'Geeks'), ('C', 'Geeks'), ('B', 4)])
    Updated Dictionary:
    dict_items([('A', 'Geeks'), ('B', 4)])

    If the Dictionary is updated anytime, the changes are reflected in the view object automatically.

     
  • 相关阅读:
    Docker的安装和配置
    SpringBoot如何添加拦截器
    使用Java执行python代码并得到结果
    Redis高可用集群之水平扩展
    Redis集群演变和集群部署
    Redis核心原理
    Redis基本数据结构
    Redis安装和配置
    Typora+PicGo+Gitee笔记方案
    视频描述(Video Captioning)近年重要论文总结
  • 原文地址:https://www.cnblogs.com/xxxsans/p/13724370.html
Copyright © 2020-2023  润新知