Dictionaries with tuples or tuples of tuples

Roy Smith roy at panix.com
Mon Feb 18 20:17:03 EST 2013


In article <c8abdc96-a47c-462a-9d6e-fcbaad1102fe at googlegroups.com>,
 Jon Reyes <everystepsayes at gmail.com> wrote:

> So I have a dictionary and the key is a number.
> [...]
> col = {"1": (0,1,2,3): "2": ((0,1,2,3),(2,3,4,5))}

The keys here are strings, not numbers.  But that's a detail.  Somewhat 
more importantly, that's a syntax error (one of the colons should be a 
comma).

> The values are either a 
> single tuple or a tuple of tuples. Is there a better way to go about 
> accessing the values of the dictionary? All the tuples contain four elements.

I would make all the values the same shape, i.e. all lists of tuples:

col = {"1": [(0,1,2,3)]: "2": [(0,1,2,3),(2,3,4,5)]}

Then you're always doing the same thing with values when you process 
them.



More information about the Python-list mailing list