You can simply use the function module hash():
def onebyte_hash(s):
return hash(s) % 256
This is what dictionaries and collections use (the hash module is the internal size of the table).
Demo:
>>> onebyte_hash('abc_123')
182
>>> onebyte_hash('any-string-value')
12
: Python 3.3 - , Python . , Python PYTHONHASHSEED ( 0 ), Python 2 3,2 3,2 - , .
hashlib.md5() ( ) :
import hashlib
try:
hashlib.md5('')
def onebyte_hash(s):
return ord(hashlib.md5(s).digest()[0])
except TypeError:
def onebyte_hash(s):
return hashlib.md5(s.encode('utf8')).digest()[0]
MD5 - , Python -.
, ; Python , .