python请问怎么吧这段文本中的的值拿下来

{'result': [{'classname': 'Face', 'top': 102, 'left': 292, 'probability': 0.9982505440711975, 'width': 232, 'height': 283}, {'classname': 'One', 'top': 101, 'left': 107, 'probability': 0.9629141092300415, 'width': 243, 'height': 319}], 'result_num': 2, 'log_id': 1524277512065889363}

打印出每个值,谢谢

给个例子:


dicts = {'result': [{'classname': 'Face', 'top': 102, 'left': 292, 'probability': 0.9982505440711975, 'width': 232, 'height': 283}, {'classname': 'One', 'top': 101, 'left': 107, 'probability': 0.9629141092300415, 'width': 243, 'height': 319}], 'result_num': 2, 'log_id': 1524277512065889363}
for k,v in dicts.items(): 
    if k!='result':
        print(f'{k}:{v}')
    else:
        for ls in dicts[k]:
            for k1,v1 in ls.items():
                 print(f'{k1}:{v1}')

img

1.字典传入,用items遍历取值


d = {'result': [
    {'classname': 'Face', 'top': 102, 'left': 292, 'probability': 0.9982505440711975, 'width': 232, 'height': 283},
    {'classname': 'One', 'top': 101, 'left': 107, 'probability': 0.9629141092300415, 'width': 243, 'height': 319}],
     'result_num': 2, 'log_id': 1524277512065889363}


def dfs(d):
    if type(d) == dict:
        for k in d:
            dfs(d[k])

    elif type(d) == list:
        for l in d:
            dfs(l)
    else:
        print(d)

dfs(d)
def list_all_dict(dict_a):
    if isinstance(dict_a, dict):  # 使用isinstance检测数据类型
        for k,v in dict_a.items():
            print(k, v)
            list_all_dict(v)


dic = {'result': [{'classname': 'Face', 'top': 102, 'left': 292, 'probability': 0.9982505440711975, 'width': 232, 'height': 283},
                  {'classname': 'One', 'top': 101, 'left': 107, 'probability': 0.9629141092300415, 'width': 243, 'height': 319}],
       'result_num': 2, 'log_id': 1524277512065889363}
list_all_dict(dic)
#



d = {'result': [
        {'classname': 'Face', 'top': 102, 'left': 292, 'probability': 0.9982505440711975, 'width': 232, 'height': 283},
        {'classname': 'One', 'top': 101, 'left': 107, 'probability': 0.9629141092300415, 'width': 243, 'height': 319}],
    'result_num': 2, 'log_id': 1524277512065889363}
mo=re.findall(r":'?([0-9a-zA-Z.]*)",str(d).replace(' ',''))
print(mo)