I have md5 hash string, e.g:
_hash = '743a0e0c5c657d3295d347a1f0a66109'
I want to write function that splits passed string to path in nginx cache format:
print hash2path(_hash, [1, 2, 3])
# outputs '7/43/a0e/743a0e0c5c657d3295d347a1f0a66109'
This is my variant:
def hash2path(_hash, levels):
hash_copy = _hash
parts = []
for level in levels:
parts.append(_hash[:level])
_hash = _hash[level:]
parts.append(hash_copy)
return '/'.join(parts)
Can you suggest better variant?