zoukankan      html  css  js  c++  java
  • python 遍历字典

    起因

    for循环遍历出 对象(字典、列表、字符串···) 的 键/值

    For循环

    • 遍历键
    dict = {'Name': 'Runoob', 'Age': 7}
    for i in dict:
        print(i)
    
    • 遍历值
    dict = {'Name': 'Runoob', 'Age': 7}
    for i in dict.values()
        print(i)
    
    • 遍历键和值
    dict.items()
    for key,value in dict.items():
    	print(key)
    	print(value)
    
    • 取列表中的第一个大字典 中 各个小字典的 键和值
        latest_list = latest_platform[0].to_dict()      # 取列表第一个值.转换成字典
        for key1, value1 in latest_list.items():        # items()以列表返回可遍历的(键, 值) 元组数组
            # print(key1) 
            # print(value1)
            if key1 == 'id':
                platform_id = value1
            if key1 == "task_category_id":
                task_category_id = value1
            if key1 == "target_image_category_id":
                target_image_category_id = value1
            if key1 == "platform_key":
                platform_key = value1
    
  • 相关阅读:
    内置对象
    js作用域对象与运用技巧
    js流程控制与函数
    JavaScript基础
    CSS3新增属性2
    CSS3新增
    前端实践
    浮动与定位
    页面布局
    表格表单视频音频
  • 原文地址:https://www.cnblogs.com/unixcs/p/13294568.html
Copyright © 2011-2022 走看看