popkey() method for dictionaries?

Alex Martelli aleax at aleax.it
Mon Nov 18 18:38:55 EST 2002


Fernando Pérez wrote:
   ...
> key _will_ trigger an exception, I'd argue that the default behavior of
> all these functions (get, pop, popitem) should be to raise an exception.

Practicality beats purity, and it would be no use for somedict.get(key) to 
be just alternative syntax for somedict[key]; while having it return None
when key not in somedict is useful to enable, for example, such use
as map(somedict.get, potentialkeys).

> Unfortunately these functions (get/pop/popitem) have already been written
> with (it seeems to me) inconsistent interfaces, and we'll just get used to

Yes, somewhat, but I think they're each pragmatic enough that keeping track
is no major chore (IMHO).


Alex




More information about the Python-list mailing list