Unfortunate exception on dict item assignment (and why aren't slices hashable?)

Aahz aahz at pythoncraft.com
Tue Jul 29 10:14:30 EDT 2003


In article <3f2627c7$0$76067$edfadb0f at dread11.news.tele.dk>,
Anders J. Munch <andersjm at dancontrol.dk> wrote:
>"Aahz" <aahz at pythoncraft.com> wrote:
>> Jeff Epler  <jepler at unpythonic.net> wrote:
>>>
>>>I don't see what's problematic about letting slices be hashable: 
>> [...]
>>Hashing them as
>>>    hash((s.start,s.stop,s.step))
>>>might be a reasonable definition.
>> 
>> Makes sense to me.  Feel free to submit a patch to SF.  ;-)
>
>I'd rather he didn't.  I prefer Python to be able to catch the bug of
>attempting to use a dict as were it a list.  For the rare case where
>using a slice key was intentional, converting to tuple form is easy
>enough.
>
>I can see that it's good for consistency to allow hashing of slices.
>However it's bad for consistency that where alist[slice] returns a
>subsequence, adict[slice] would return a single element.

Fair enough.  Note carefully that I said "submit a patch" -- that
doesn't guarantee that the patch will be accepted, and it's quite likely
that it won't be.  But "submit a patch" is usually a good way to get
people to shut up.  ;-)
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

This is Python.  We don't care much about theory, except where it intersects 
with useful practice.  --Aahz




More information about the Python-list mailing list