Python查询信息

Python查找档案信息要怎么根据多个关键词(比如姓名和学院组合查询)一起查找。

def search_file(file_name, name, college):
    results = []
    with open(file_name, "r") as file:
        for line in file:
            if name in line and college in line:
                results.append(line)
    return results

file_name = "students.txt"
name = "John Doe"
college = "College of Arts and Sciences"
results = search_file(file_name, name, college)

for result in results:
    print(result)

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^