What is the shortest hash (in filename-usable form, like a hexdigest) available in python? My application wants to save cache files for some objects. The objects mu
We use hashlib.sha1.hexdigest(), which produces even longer strings, for cache objects with good success. Nobody is actually looking at cache files anyway.
The builtin hash function of strings is fairly collision free, and also fairly short. It has 2**32
values, so it is fairly unlikely that you encounter collisions (if you use its abs value, it will have only 2**31
values).
You have been asking for the shortest hash function. That would certainly be
def hash(s):
return 0
but I guess you didn't really mean it that way...