问题在于声明addressToIdMap = {}
.您在模块级别上声明了它,因此在您Update_Dictionary
第二次调用函数之前它不会被清除.
你需要把它移到里面 Update_Dictionary
def Update_Dictionary(physicalAddrList,cmdId,opcode): addressToIdMap = {} for address in physicalAddrList: list = GetBufferId() addressToIdMap[address] = list mydict[cmdId,opcode] = addressToIdMap