[Python-Dev] Dict.popitem(key=None)

Guido van Rossum guido@python.org
Wed, 03 Apr 2002 19:55:03 -0500


> Dan Parisien posted a small feature request about three months ago:
> http://sourceforge.net/tracker/index.php?func=detail&aid=495086&group_id=5470&atid=355470
> 
> The current behavior of popitem is to return and remove an arbitrary
> key/value pair from a dictionary.  With the optional argument, Dan
> proposes that a specific key/value pair be returned and removed.
> Without the optional argument, the behavior would be unchanged.
> 
> I think this is a great idea.  Like .get() and .setdefault(), this
> provides a fast, explicit alternative to a commonly used series of
> dictionary operations.  The speed improvement comes from doing a
> single lookup for retrieving the item and then deleting it.  Like
> the optional argument in list.pop(i), the extra ability is added
> without cluttering the default case.
> 
> If we can agree that this should be done and accepted, I'll
> volunteer to write the patch.

Without having thought too much about it, I'm inclined to agree.  Go
ahead and submit the patch to SF.  If the populace doesn't want it,
though, I will deny any responsibility. :-)

--Guido van Rossum (home page: http://www.python.org/~guido/)