student_list = [{'姓名': 'yc', '学号': '0001', '成绩': '92'},
{'姓名': 'qq', '学号': '0002', '成绩': '88'},
{'姓名': 'ee', '学号': '0003', '成绩': '95'}]
# print(student_list)
# print(student_list[1].get("姓名"))
# 根据字典的部分值查找到字典列表的完整值函数
def find_dict_by_value(dicts, key, value):
for d in dicts:
if key in d and d[key] == value:
return d
return None
result = find_dict_by_value(student_list, '学号', "0002")
print(result)
# 根据字典的部分值查找到字典列表的完整值函数
# 并返回其在列表中的索引位置
def index_dict_by_value(dicts, key, value):
for d in dicts:
if key in d and d[key] == value:
number = dicts.index(d)
return number
return None
result_1 = index_dict_by_value(student_list, '学号', "0002")
print(result_1)
# 根据字典的部分值查找到字典列表的完整值函数
# 并返回其在列表中的索引位置
# 并删除其完整的信息
def del_dict_by_value(dicts, key, value):
for d in dicts:
if key in d and d[key] == value:
number = dicts.index(d)
del student_list[number]
print(f"已删除信息{d}")
del_dict_by_value(student_list, '学号', "0002")
print(student_list)