Author steven.daprano
Recipients Dima.Tisnek, steven.daprano
Date 2018-12-28.03:35:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
> In the old days I'd just `hash(some_variable)` but of course now I cannot.

I'm sorry, I don't understand... why can't you?

py> text = "NOBODY expects the Spanish Inquisition!"
py> hash(text)

There's also this:

py> hashlib.md5(text.encode('utf-8')).digest()

although it might be a bit expensive if you don't care about security and too weak if you do. Can you explain why hash() isn't suitable?

For what's its worth, I wouldn't use sum() to generate a hash since it may be unbounded and may not be "mixed up" enough. If you can't hash a string, perhaps you can hash a tuple of ints?

py> hash(tuple(map(ord, text)))
py> hash(tuple(map(ord, text+"\0")))
Date User Action Args
2018-12-28 03:35:21steven.dapranosetrecipients: + steven.daprano, Dima.Tisnek
2018-12-28 03:35:19steven.dapranosetmessageid: <>
2018-12-28 03:35:19steven.dapranolinkissue35600 messages
2018-12-28 03:35:19steven.dapranocreate