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

Erik Max Francis max at alcyone.com
Mon Jul 21 00:04:29 EDT 2003


Jeff Epler wrote:

> I'd have expected something like 'TypeError: unslicable type'
> meaning that you can't slice a dict, not that slice()s aren't
> hashable.

Slicing is not a feature of the mapping interface; it's not entirely
clear what it should mean.  All mapping interfaces need are keys that
are hashable; it doesn't make any kind of requirements about how those
keys related to each other.  So slicing a mapping interface is something
that simply may not make any sense at all in some cases.

If you really _do_ want to take a range out of a dictionary and know
that it has some meaning, you should probably do the slicing on the
_list of keys_ (D.keys()) -- because there is no concept of an ordering
of keys in a dictionary.

-- 
   Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
 __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/  \ It is much safer to obey than to rule.
\__/  Thomas a Kempis




More information about the Python-list mailing list