我是 Python 的新手,所以我欢迎其他方法。
我有一个字典列表(从文件中读取)。 现在我有一堆额外的词典,我想添加到这个列表中,但前提是它们不在原始列表中。
但是,我要求“不在原始列表中”由自定义比较函数定义,而不是 Python 默认使用的任何内容。
更具体地说,我想比较字典中的某些键/值对,如果它们相同,则为表达式返回“true”。
myList = ReadFromFile...
newList = ReadFromFile...
for item in newList:
if item not in myList: #I want custom behavior for this "in"
myList.append(item)
最佳答案
关于python - 如何在 Python 中为 "in"关键字指定自定义比较器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9898617/