I'm new to pythonPython and I'm trying to convert between Microsoft GUIDs and plain hex strings. My code (python 3) looks like this:
def hex_to_guid(hex):
h = binascii.unhexlify(hex)
return '-'.join(map(bytes.decode, map(
binascii.hexlify, (h[0:4][::-1], h[4:6][::-1], h[6:8][::-1], h[8:10], h[10:]))))
def guid_to_hex(guid):
g = binascii.unhexlify(guid.translate(str.maketrans('', '', '-')))
return ''.join(map(bytes.decode, map(
binascii.hexlify, (g[3::-1], g[5:3:-1], g[7:5:-1], g[8:]))))
I suspect this may not beebe very readable. Am I being too clever?