我有两本字典
user_hash = {
"as34": "98354897394053452345",
"ad23" : "2131313111313131313",
"ae23": "31245512121521212121"
}
active_user_hash = [
{"field0": "231634684712313"},
{"field0" : "23145454564120"},
{"field0" : "215465464133313"}]
实际上,在这些字典和字典列表中有数百万个键值对。其目的是循环遍历dictionary 1的每个值,并使用自定义函数将其与dictionary值的第二个列表进行比较。我不能使用这种逻辑的任何排序或优化,因为每个元素之间的比较都是必要的。哪种方法最快?你知道吗
电流循环需要11分钟!我想把时间缩短到几秒钟。你知道吗
for index, id_hash in user_hash.iteritems():
try:
for element in active_user_hash:
match = custom_comparison_function_algo(id_hash, element['field0'])
if match < 40:
print 'success'
except Exception as err:
print err
import distance
def custom_comparison_function_algo(hash1, hash2):
levenshtein_dist = distance.nlevenshtein(hash1, hash2, method=1)
jaccard_dist = distance.jaccard(hash1, hash2)
return int(((levenshtein_dist + jaccard_dist) / 2) * 100)
我尝试过numpy矢量化,但我的头绕不过去。你知道吗
如果你创建了一个列表(或者一个由Ev提议的集合)。Kounis),然后在列表理解中运行函数?你知道吗
相关问题 更多 >
编程相关推荐