Steven D'Aprano <steve+pyt...@pearwood.info> added the comment:
> 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 ---------- nosy: +steven.daprano _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue35600> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com