Vernon Cole wrote: > What a nifty script! I love it! > Here's my version. I tested using a 800 KByte image file and it runs > in a blink. Dictionary access in Python is very fast. > <code> > counter = {} > > for bytes in open('c:\\temp\\16.jpg', "rb").read(): > try: > counter[bytes] += 1 > except KeyError: > counter[bytes] = 1 > > for key in sorted(counter.keys()): > print '%s: %d,' % (repr(key),counter[key]), > print > </code>
Since the size of the universe is small and known in advance, a list would be faster yet: counter = [0]*256 for bytes in open('c:\\temp\\16.jpg', "rb").read(): counter[ord(bytes)] += 1 for key,cnt in enumerate(counter): print '%d: %d,' % (key,cnt), -- Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. _______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32