Message332636
> 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)
1245575277
There's also this:
py> hashlib.md5(text.encode('utf-8')).digest()
b'@\xfb[&\t]\x9c\xc0\xc5\xfcvH\xe8:\x1b]'
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)))
-816773268
py> hash(tuple(map(ord, text+"\0")))
667761418 |
|
Date |
User |
Action |
Args |
2018-12-28 03:35:21 | steven.daprano | set | recipients:
+ steven.daprano, Dima.Tisnek |
2018-12-28 03:35:19 | steven.daprano | set | messageid: <1545968119.99.0.931531567008.issue35600@roundup.psfhosted.org> |
2018-12-28 03:35:19 | steven.daprano | link | issue35600 messages |
2018-12-28 03:35:19 | steven.daprano | create | |
|