python json字典列表,按指定相同的键值对,合并到一个列表中

undergraduate_result =[

    {"major": "Sociology1","href": "https://as.cornell.edu/sociology-major","note": "","type": "Bachelor's","college": "College of Arts and Sciences"},

    {"major": "Sociology2","href": "https://as.cornell.edu/sociology-major","note": "","type": "Bachelor's","college": "College of Arts and Sciences"},

    {"major": "Sociology3","href": "https://as.cornell.edu/sociology-major","note": "","type": "Bachelor's","college": "College of Arts and Sciences"},

    {"major": "Sociology4","href": "https://as.cornell.edu/sociology-major","note": "","type": "Bachelor's","college": "College of Arts and Sciences"}

]

undergraduate_json = {}
for undergraduate in undergraduate_result:
  if undergraduate["college"] in undergraduate_json:
    undergraduate_json[undergraduate["college"]].append(undergraduate)
  else:
    undergraduate_json[undergraduate["college"]] = [undergraduate]

print(undergraduate_json)

==================以下为输出==========================

python  json字典列表,按指定相同的键值对,合并到一个列表中

 

上一篇:Flutter 2.10 正式发布,包含 Windows 平台正式版,快来看看有什么新内容


下一篇:(ElasticSearch)中文字符串精确搜索 term 搜不到结果