def match(model_key_words, data_key_words):
model_name_diff = {}
model_name_list = list(model_key_words.keys())
data_name_list = list(data_key_words.keys())
if 'image' in data_name_list:
data_name_list.remove('image')
print('before contact info match:', len(model_name_list), model_name_list)
# contact information match
for model_name in model_name_list[:]:
if set(data_name_list) < set(list(model_key_words[model_name].keys())):
same_numb = 0
diff_numb = 0
for key in data_name_list:
if data_key_words[key] <= model_key_words[model_name][key]:
same_numb += 1
diff_numb += model_key_words[model_name][key] - data_key_words[key]
if same_numb < len(data_name_list):
model_name_list.remove(model_name)
else:
model_name_diff[model_name] = diff_numb
else:
model_name_list.remove(model_name)
print('after contact info match:', len(model_name_list), model_name_list)
return model_name_list, model_name_diff
参考资料
python列表遍历循环中删除元素出错的问题
python判断一个列表是否包含另一个列表_Python判断一个list中是否包含另一个l。。。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)