[Python-bugs-list] [ python-Feature Requests-805255 ] remove/discard method for dict objects.

SourceForge.net noreply at sourceforge.net
Sat Sep 13 22:42:45 EDT 2003


Feature Requests item #805255, was opened at 2003-09-12 14:08
Message generated for change (Comment added) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=805255&group_id=5470

Category: None
Group: None
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: Jeremy Fincher (jemfinch)
Assigned to: Nobody/Anonymous (nobody)
Summary: remove/discard method for dict objects.

Initial Comment:
dict objects already provide a method for getting from

the dictionary (possibly returning a default value) so

as to avoid raising KeyError.  But there's no way to

remove an item that may or may not be in a dictionary

from a dictionary without risking raising KeyError.



I think there should be a method to remove a key if it

is in the dictionary, but to do nothing if it isn't. 

I'd suggest calling it .remove, but the sets.Set type

offers this functionality as .discard, so perhaps

that's a better name.

----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2003-09-13 21:42

Message:
Logged In: YES 
user_id=80475

That functionality is already provided by dict.pop() in Py2.3:



>>> d = {}

>>> d.pop('a', 1)

1

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=805255&group_id=5470



More information about the Python-bugs-list mailing list