Welcome, guest | Sign In | My Account | Store | Cart
def group(a, *ns):
    for n in ns:
        a = [a[i:i+n] for i in xrange(0, len(a), n)]
    return a

def join(a, *cs):
    return [cs[0].join(join(t, *cs[1:])) for t in a] if cs else a

def hexdump(data):
    toHex = lambda c: '{:02X}'.format(ord(c))
    toChr = lambda c: c if 32 <= ord(c) < 127 else '.'
    make = lambda f, *cs: join(group(map(f, data), 8, 2), *cs)
    hs = make(toHex, '  ', ' ')
    cs = make(toChr, ' ', '')
    for i, (h, c) in enumerate(zip(hs, cs)):
        print '{:010X}: {:48}  {:16}'.format(i * 16, h, c)

Diff to Previous Revision

--- revision 3 2015-05-29 10:41:07
+++ revision 4 2015-05-29 10:44:47
@@ -1,8 +1,7 @@
 def group(a, *ns):
-    r = a
     for n in ns:
-        r = [r[i:i+n] for i in xrange(0, len(r), n)]
-    return r
+        a = [a[i:i+n] for i in xrange(0, len(a), n)]
+    return a
 
 def join(a, *cs):
     return [cs[0].join(join(t, *cs[1:])) for t in a] if cs else a

History