Perlish dictionary behavior

Fred Allen fallen at
Wed Jun 9 02:53:48 CEST 2004

Mr. Brewer:

I fruitlessly tried your "thing counter", as you can see below. 

>>> class AllThingsStartAtZero(dict):
... 	def getitem (self, key):
... 		return dict.get(self, key, 0)
>>> thingCounts = AllThingsStartAtZero() for thing in 
>>> ('a','b','c','d','a'):
... 	thingCounts[thing] += 1
Traceback (most recent call last):
  File "<interactive input>", line 2, in ?
KeyError: 'a'
>>> thingCounts

Reason tells me it should work for me using...

PythonWin 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit
(Intel)] on win32. it did for you. The runtime interpreter, however, says
otherwise. Can you see what I've done wrong...I can't?

With thanks in advance, I am,

Respectfully yours,

Fred Allen

More information about the Python-list mailing list