# HG changeset patch # User Atul Varma # Date 1213167170 25200 # Node ID 0315da3546b336465284c272fee53ac068edc445 # Parent 89325a6a204d32a1fef1053ade6414cf34d74210 Added a note about dictionary keys being any immutable. diff -r 89325a6a204d -r 0315da3546b3 PythonForJsProgrammers.txt --- a/PythonForJsProgrammers.txt Tue Jun 10 23:49:06 2008 -0700 +++ b/PythonForJsProgrammers.txt Tue Jun 10 23:52:50 2008 -0700 @@ -488,6 +488,18 @@ >>> "Hello %(name)s, I need %(money)d dollars." % d 'Hello bob, I need 5 dollars.' +Keys for dictionaries can actually be any immutable type; this means +that, for instance, tuples can be used as keys: + + >>> a = {(1,2) : 1} + +But lists can't: + + >>> b = {[1,2] : 1} + Traceback (most recent call last): + ... + TypeError: list objects are unhashable + Python dictionaries generally aren't used to create arbitrary objects like they are in Javascript; they don't have prototypes, nor do they have meta-methods. Instead, classes are used to do that sort of