Thanks guys for your input

As I need this for larger files (couple of tens even hundrets of MB) I
tested your suggestion and it seems that dict method is fastest.

I ended with this:

----------------------------
import sys

try:
    counter = {}

    for bytes in open(sys.argv[1], "rb").read():
        try:
            counter[bytes] += 1
        except KeyError:
            counter[bytes] = 1

    peak = max(counter.values())

    for key in sorted(counter.keys()):
        print '%02x: %08d %s' % (ord(key), counter[key], '-' * (66 * 
counter[key]/peak))

except Exception, e:
    print e
----------------------------

Cheers
_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to