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
    
  • 相关阅读:
    display
    盒子模型
    css样式
    修改页面标题前的图标
    form表单
    html中列表
    代码书写格式
    dw中的超链接
    硬盘的访问,程序重定位和加载
    Bochs调试指令
  • 原文地址:https://www.cnblogs.com/unixcs/p/13294568.html
Copyright © 2011-2022 走看看