@nilam Just to be pedantic, I simplified hexdump a bit. This is old code, collected when I started with Python.
FILTER=''.join([(len(repr(chr(x)))==3) and chr(x) or '.' for x in range(256)])
def hexdump(src, length=16):
N=0; result=''
while src: # loop through string
s,src = src[:length],src[length:]
hexa = ' '.join(["%02X"%x for x in s])
s = ''.join([FILTER[_] for _ in s])
result += "%04X %-*s %s\n" % (N, length*3, hexa, s)
N += length
return result
I have my doubts whether I did all of that myself at that time, especially the FILTER= .. expression.