python 遍历字典 提取指定key值value

版权声明:本文为博主原创文章,可以自由转载。 https://blog.csdn.net/u010953692/article/details/83618811

python 查找字典key的值value

1,简单字典查找key值

#! /usr/local/bin/python3
# coding:utf-8
"""
遍历字典 提取key值value
"""
import json
file = "/Users/y50/data"
soulData = open(file , 'r').read()
data = json.loads(soulData)
print ("data type : " , type(data))
print ("data : " , data)
data_key = "name"
for key in data.keys():
    if key == data_key:
        print (data[key])
    
print ("测试")
data type :  <class 'dict'>
data :  {'name': 'ni', 'city': 'tt', 'id': 2256}
ni
测试

参考:

  1. python,字典中如何根据value值取对应的key值
  2. 无限遍历,Python实现在多维嵌套字典、列表、元组的JSON中获取数据
  3. Python字典嵌套字典的情况下获取某个key的value

猜你喜欢

转载自blog.csdn.net/u010953692/article/details/83618811
今日推荐