我目前有以下代码:
from itertools import permutations
import hashlib
def hash_f(x):
h = hashlib.md5(x)
return int(h.hexdigest(),base=16)
value = raw_input("Enter a value: ")
possibleValues = 'a'
for p in permutations(possibleValues):
if hash_f(value) == hash_f(possibleValues):
print "MATCH"
(导入和使用排列现在是一个占位符,一旦这个问题得到解决,它将被更多地使用)
我想知道的是,是否可以遍历列表并将其值替换为该值的散列形式。使用我当前的hash_f(x)
函数不适用于列表,这是问题所在。
感谢您提前获取任何帮助,如果您需要更多信息,请与我们联系!
答案 0 :(得分:2)
我不明白你的代码片应该做什么,但你的问题似乎可以用列表理解来回答。
from hashlib import md5
input_list = ['a','b','c','d','e']
hashed_list = [int(md5(x).hexdigest(), base=16) for x in input_list]
# Do whatever you wanted to do with the list of hashes....