[Python-ideas] Why no dict.discard?

MRAB python at mrabarnett.plus.com
Tue Aug 7 22:42:38 CEST 2012

On 07/08/2012 21:30, Laurens Van Houtven wrote:
> On 07 Aug 2012, at 22:25, MRAB <python at mrabarnett.plus.com> wrote:
>> The 'set' class has a 'discard' method, but dict doesn't.
>> I know that I can just delete the key and catch the exception if it's
>> absent, but I can also 'remove' a member from a set and catch the
>> exception if it's absent, OR just 'discard' it to avoid an exception.
>> How much interest would there be in adding 'discard' to dict too?
> FWIW I use d.pop(k, None) to mean "just remove this already regardless
 > of whether or not it's present now".
Thanks for that.

More information about the Python-ideas mailing list