我正在为我的学校网站做一个刮板,这个网站会自动得到今天的作业。
[
{
"id": "1523958",
"studentId": "8326",
"assignmentId": "35074",
"diaryType": "cw",
"diaryId": "35074",
"subject": "URDU",
"title": "اچھے آداب و اطوار",
"description": "9F Maymaar - Classwork posted",
"bRead": "1",
"date": "Fri, 04/11/2022",
},
{
"id": "1520938",
"studentId": "8426",
"assignmentId": "35013",
"diaryType": "cw",
"diaryId": "35013",
"subject": "SOCIAL STUDIES",
"title": "The Globe and Maps ",
"description": "5C Maymaar - Classwork posted",
"bRead": "0",
"date": "Fri, 04/11/2022",
"download": "2bf0c7b51af0cfb1023261dd7b8b4f8f.jpg",
},
{
"id": "1520624",
"studentId": "8426",
"assignmentId": "35007",
"diaryType": "cw",
"diaryId": "35007",
"subject": "MATHEMATICS",
"title": "Percentage ",
"description": "5C Maymaar - Classwork posted",
"bRead": "0",
"date": "Fri, 04/11/2022",
},
{
"id": "1520530",
"studentId": "8426",
"assignmentId": "35005",
"diaryType": "cw",
"diaryId": "35005",
"subject": "ENGLISH A",
"title": "Paragraph writing ",
"description": "5C Maymaar - Classwork posted",
"bRead": "0",
"date": "Fri, 04/11/2022",
},
{
"id": "1517928",
"studentId": "8326",
"assignmentId": "34952",
"diaryType": "cw",
"diaryId": "34952",
"subject": "PHYSICS",
"title": "Homework",
"description": "9F Maymaar - Classwork posted",
"bRead": "1",
"date": "Fri, 04/11/2022",
},
{
"id": "1513747",
"studentId": "8426",
"assignmentId": "34887",
"diaryType": "gn",
"diaryId": "34887",
"subject": None,
"title": "General notice ",
"description": "5C Maymaar - Notice posted",
"bRead": "0",
"date": "Thu, 03/11/2022",
},
{
"id": "1508998",
"studentId": "8426",
"assignmentId": "34787",
"diaryType": "cw",
"diaryId": "34787",
"subject": "SOCIAL STUDIES",
"title": "Map reading skills ",
"description": "5C Maymaar - Classwork posted",
"bRead": "0",
"date": "Thu, 03/11/2022",
},
]上面看到的是一个列表,我想做的是:如果studentId = 8426,如果日期=某事:发送AssignmentiId到显示
我试着做我自己,但我不知道如何处理这个问题,我如何阅读每一本字典,检查每一个键和它的价值,然后打印出另一个键在同一本词典?
for key, value in diary:
if key == "date":
if value == "Fri, 04/11/2022":
print(key, value)发布于 2022-11-05 10:28:10
根据注释,您可以遍历列表并检查您的条件。例如(lst是问题中的列表):
for d in lst:
if d["studentId"] == "8426" and d["date"] == "Fri, 04/11/2022":
print(d["assignmentId"])指纹:
35013
35007
35005发布于 2022-11-05 10:33:07
diaries = [
{
"id": "1523958",
"studentId": "8326",
"assignmentId": "35074",
"diaryType": "cw",
"diaryId": "35074",
"subject": "URDU",
"title": "اچھے آداب و اطوار",
"description": "9F Maymaar - Classwork posted",
"bRead": "1",
"date": "Fri, 04/11/2022",
},
{
"id": "1520938",
"studentId": "8426",
"assignmentId": "35013",
"diaryType": "cw",
"diaryId": "35013",
"subject": "SOCIAL STUDIES",
"title": "The Globe and Maps ",
"description": "5C Maymaar - Classwork posted",
"bRead": "0",
"date": "Fri, 04/11/2022",
"download": "2bf0c7b51af0cfb1023261dd7b8b4f8f.jpg",
},
{
"id": "1520624",
"studentId": "8426",
"assignmentId": "35007",
"diaryType": "cw",
"diaryId": "35007",
"subject": "MATHEMATICS",
"title": "Percentage ",
"description": "5C Maymaar - Classwork posted",
"bRead": "0",
"date": "Fri, 04/11/2022",
},
{
"id": "1520530",
"studentId": "8426",
"assignmentId": "35005",
"diaryType": "cw",
"diaryId": "35005",
"subject": "ENGLISH A",
"title": "Paragraph writing ",
"description": "5C Maymaar - Classwork posted",
"bRead": "0",
"date": "Fri, 04/11/2022",
},
{
"id": "1517928",
"studentId": "8326",
"assignmentId": "34952",
"diaryType": "cw",
"diaryId": "34952",
"subject": "PHYSICS",
"title": "Homework",
"description": "9F Maymaar - Classwork posted",
"bRead": "1",
"date": "Fri, 04/11/2022",
},
{
"id": "1513747",
"studentId": "8426",
"assignmentId": "34887",
"diaryType": "gn",
"diaryId": "34887",
"subject": None,
"title": "General notice ",
"description": "5C Maymaar - Notice posted",
"bRead": "0",
"date": "Thu, 03/11/2022",
},
{
"id": "1508998",
"studentId": "8426",
"assignmentId": "34787",
"diaryType": "cw",
"diaryId": "34787",
"subject": "SOCIAL STUDIES",
"title": "Map reading skills ",
"description": "5C Maymaar - Classwork posted",
"bRead": "0",
"date": "Thu, 03/11/2022",
},]
for diary in diaries:
if diary['studentId'] == '8326' and diary['date'] == 'something':
print(diary['assignmentId'])https://stackoverflow.com/questions/74326899
复制相似问题