On Mon, 06 Dec 2004 13:08:15 -0800, Scott David Daniels
<[EMAIL PROTECTED]> wrote:
> Zak Arntson wrote:
> > On Fri, 03 Dec 2004 14:48:30 -0800, Scott David Daniels
> Most likely so.  Possibly an equal amount of has work -- hash of a pair
> is a function of hashes of the lelements, but fewer trips in and out of
> the interpretter.  So, one less lookup, less refcount fiddling, and
> fewer dispatches through the interpretter.
> 
> The real advantage is clarity: the inner dictionaries in a dict-of-dict
> implementation have no real "meaning."  The extra overhead (in the mind
> of the program reader) involved in creating inner dictionaries at
> appropriate times makes the code harder to understand.
> 
> --Scott David Daniels
> [EMAIL PROTECTED]

I feel differently (though I'd accept being in the minority on this
one). If you have a dictionary of tuples where the first member is an
often-repeated value, then it makes more sense (again, to me) to split
it up.

So if I see:
{("None", "Enter"): enter_state_None,
 ("None", "During"): during_state_None,
 ("None", "Leave"): leave_state_None,
 ("LWait", "Enter"): enter_state_LWait,
 ("LWait", "During"): during_state_LWait,
 ("LWait", "Leave"): leave_state_LWait}

I want to split it up. This is more intuitive for me because it shows
an obvious one-many relationship between the outer keys and the inner
keys.
{"None": {"Enter": enter_state_None, "During": during_state_None,
"Leave": leave_state_None},
 "LWait": {"Enter": enter_state_LWait, "During": during_state_Lwait,
"Leave": leave_state_LWait}}


I have to confess to not knowing whether one way is more "Pythonic"
than the other. The first method is mostly easier to code with, but
doesn't explicitly state a one-many relationship. The second give
lengthier code for most operations.

-- 
Zak Arntson
http://www.harlekin-maus.com - Games - Lots of 'em
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to