On 13 Jun 2005 01:04:53 -0700, rumours say that "Raymond Hettinger" <[EMAIL PROTECTED]> might have written:
># Professional driver on a closed course. ># Don't try this at home. > >data = """ >rose, 1, 500 >lilac, 1, 300 >lilly, 1, 400 >rose, 0, 100 >""" > >data = data.replace(', 1, ', ' += ') >data = data.replace(', 0, ', ' -= ') > >class DefaultDict(dict): > def __getitem__(self, key): > return self.get(key, 0) > >d = DefaultDict() >exec data in {}, d >print d.items() For kids trying this at home, note that it only works if the descriptor is a valid Python identifier. -- TZOTZIOY, I speak England very best. "Be strict when sending and tolerant when receiving." (from RFC1958) I really should keep that in mind when talking with people, actually... -- http://mail.python.org/mailman/listinfo/python-list