Neil Cerutti wrote: > On 2007-04-21, Steven D'Aprano <[EMAIL PROTECTED]> wrote: >> On Fri, 20 Apr 2007 15:36:00 -0700, [EMAIL PROTECTED] wrote: >>>> The article explains that, amongst other things, tuples are >>>> faster than lists, so if you are working with constant values >>>> (inmutables) they are more indicated than lists. >>> Thanks. I thought Python's design wasn't so concerned with >>> optimizations. Adding a new type "just" for optimization >>> reasons seems perhaps unnecessary. I could be wrong. >> It's times like this I want to cry... >> >> >>>>> adict = {(1,2): "parrot"} >> Try replacing that tuple with a list. "Just optimization" my eye! > > So the question becomes: Why do Python dictionaries require keys > to be of an immutable type? > Because otherwise people would expect to be able to use a list to select a dictionary entry even after they'd modified elements of the list after creating the dictionary entry. Which they couldn't. So Python doesn't let them use lists.
regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Recent Ramblings http://holdenweb.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list