Dictionaries with tuples or tuples of tuples

Dave Angel davea at davea.name
Tue Feb 19 02:51:50 CET 2013

On 02/18/2013 08:38 PM, Jon Reyes wrote:
> Hi Mark. Well, doesn't iteritems() work the same? or am I missing something? By the way I'm sure I read the dictionaries part of Python but I'm unsure if it would take int's as a key for dictionaries. I've been weaned on Java where the keys of hashmaps are always Strings.
> PS: Just checked, wow I could use ints as keys. Awesome!

The keys to a dictionary may be any immutable type.  That includes str, 
int, and tuple, but it also can include any other class that meets a 
couple of simple criteria.  In simplified language, the only requirement 
is that the key object cannot change its value or hash, so that if two 
key objects are equal, they stay equal, and if they differ, they stay 


More information about the Python-list mailing list