123456789101112131415161718192021import pprintf = open('/u1/junk/shakespeare.txt', 'r')contents = f.read()f.close()count = {}# One way#for character in contents:#count.setdefault(character, 0)#count[character] = count[character] + 1# The get method for a dictionary accepts two parameters# The first is the lookup value# The second is the default value if there is no recordfor character in contents:count[character] = count.get(character, 0) + 1pprint.pprint(count)