[Patches] [ python-Patches-633374 ] nondestructive dict.popitem and Set.pop
noreply@sourceforge.net
noreply@sourceforge.net
Mon, 04 Nov 2002 22:31:33 -0800
Patches item #633374, was opened at 2002-11-04 12:15
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=633374&group_id=5470
Category: Library (Lib)
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: John Williams (johnw42)
Assigned to: Nobody/Anonymous (nobody)
Summary: nondestructive dict.popitem and Set.pop
Initial Comment:
This patch (relative to the latest Python CVS tree)
adds a "pickitem" method to the builtin dict class and
a "pick" method to the BaseSet class. These methods
are analogs of "dict.popitem" and "Set.pop", but they
don't remove the item they return from the dict/set.
This patch *does not* update the documentation.
This is my system:
Linux 2.4.2-2 #1 i686 unknown
----------------------------------------------------------------------
>Comment By: Raymond Hettinger (rhettinger)
Date: 2002-11-05 01:31
Message:
Logged In: YES
user_id=80475
dict.popitem() was added because the it could retrieve and
delete a key/value pair without hashing -- there were no
existing methods which could achieve the same result.
In contract, the dict.pickitem() patch doesn't appear to
offer a differential advantage over dict.iteritems().next() for
retrieving an arbitrary (hash order) key/value pair.
Also, since successive calls to pickitem() retrieve the same
pair, it doesn't appear to be useful in a loop or warrant a C
speed optimization
----------------------------------------------------------------------
Comment By: Neal Norwitz (nnorwitz)
Date: 2002-11-04 18:54
Message:
Logged In: YES
user_id=33168
Fixed the Summary, lest someone think you were making a
personal problem public. :-)
Seriously though...I haven't looked at the patch, but could
you explain the rationale/benefit? Is this likely to be
useful to many people or is it fairly limited? Couldn't you
do dict.items()[0] if you wanted a random value?
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=633374&group_id=5470