第七讲作业-元组,字典,集合

1.a = {"name":"123","data":{"result":[{"src":"python1"},{"src":"python2"},{"src":"python3"}]}} 找到python1/python2/python3

a = {"name":"123","data":{"result":[{"src":"python1"},{"src":"python2"},{"src":"python3"}]}}
print(a["data"]["result"][0]["src"],a["data"]["result"][1]["src"],a["data"]["result"][2]["src"])

 

2.有如下值集合[11,22,33,44,55,66,77,88,99,90], 将所有大于66的值保存至字典的第一个key的值中,将小于66值保存至第二个key的值中。

set = {11,22,33,44,55,66,77,88,99,90}
set1 = list(set)
set2 = {}
value1 = []
value2 = []
for i in set1:
    if i > 66:
        value1.append(i)
    elif i < 66:
        value2.append(i)
set2["大于66的值"] = value1
set2["小于66的值"] = value2

print(set2)

©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页