[Python-Dev] Dict.popitem(key=None) (original) (raw)
Raymond Hettinger python@rcn.com
Wed, 3 Apr 2002 18:26:17 -0500
- Previous message: [Python-Dev] [development doc updates]
- Next message: [Python-Dev] Dict.popitem(key=None)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
This is a multi-part message in MIME format.
------=_NextPart_000_0029_01C1DB3D.0B3698E0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Dan Parisien posted a small feature request about three months ago: = http://sourceforge.net/tracker/index.php?func=3Ddetail&aid=3D495086&group= _id=3D5470&atid=3D355470
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.
Raymond Hettinger
Before
value =3D adict[key] del key return (key, value)
After
return adict.popitem(key)
------=_NextPart_000_0029_01C1DB3D.0B3698E0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
------=_NextPart_000_0029_01C1DB3D.0B3698E0--
- Previous message: [Python-Dev] [development doc updates]
- Next message: [Python-Dev] Dict.popitem(key=None)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]