On Sep 19, 3:06 pm, Paddy <[EMAIL PROTECTED]> wrote: > On Sep 19, 9:58 pm, Karthik Gurusamy <[EMAIL PROTECTED]> wrote: > > > Since we know hashing is used, all that is needed is, a well-defined > > way to construct a hash out of a mutable. "Given a sequence, how to > > get a hash" is the problem. If later the given sequence is different, > > that's not the dict's problem. > > Oh it is possible to construct a hash from a mutable. What is > difficult is creating the same hash when the mutable mutates.
Why? There is no reason that the dict should maintain the same hash, after all the user is calling with a different sequence as key (after the mutation). There seems to be an underlying assumption that the dictionary key- >value mapping should somehow maintain the mapping even when the key changes behind its back. The contract could very well be, hey if you give me a different sequence later (by mutating the one you added), don't expect me to find it in the dictionary. >Or > indeed working out what it means when a hash key mutates and you > access the dictionary. > Ignoring this gives the programmer a big problem hence the limitation. > > I don't think you have a better solution. But why would a programmer expect to find the match, when his/her code has changed the sequence (or has somehow let the hash key mutate) from the time of dictionary addition. If I did, a = [10, 20] and I did d[a]= 'foo', then a.append(30). If dict complains key error on d[a] now, I won't be surprised. If I do d[[10, 20, 30]], I will be surprised if it doesn't find the item. Of course, in today's behavior the above is syntax error. Karthik > > - Paddy. -- http://mail.python.org/mailman/listinfo/python-list