Any way to use a range as a key in a dictionary?

Paul Rubin http
Sat Mar 28 05:08:04 CET 2009

Carl Banks <pavlovevidence at> writes:
> Not necessarily: if the hash calculation for x is expensive enough the
> get version would still be faster. 

Yeah, the get version with the special marker value is just ugly IMO,
as is the version with exceptions.  Maybe there should be a two-value

   found, value = d.xget(key [,default])

xget returns a 2-tuple, the first element of which is a boolean
indicating whether the key was present.  The second is the value (if
present) or the default (if supplied), or None.

Another possible interface:

   values = d.vget(key)

This returns a list containing the values found for the key, or an
empty list if none are found.  In the case where d is a dict, 
the list is therefore always either 1-element or empty, but one
could imagine other mapping types where longer lists could come back.

More information about the Python-list mailing list