On Fri, Mar 5, 2010 at 5:22 PM, Pete Emerson <pemer...@gmail.com> wrote:
> I've been wrestling with dicts. I hope at the very least what I > discovered helps someone else out, but I'm interested in hearing from > more learned python users. > > I found out that adding a two dimensional element without defining > first dimension existing doesn't work: > > >>> data = {} > >>> data['one']['two'] = 'three' > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > KeyError: 'one' > >>> data['one'] = {} > >>> data['one']['two'] = 'three' > >>> print data > {'one': {'two': 'three'}} > > Perhaps a better idiom for what you are doing would be to use tuples as the keys: (I don't have a handy Python interpreter, so untested) data = {} data[('one', 'two')] = 'three'
-- http://mail.python.org/mailman/listinfo/python-list