[Patches] [ python-Patches-684010 ] extending dict functionality

SourceForge.net noreply@sourceforge.net
Mon, 10 Feb 2003 08:42:49 -0800


Patches item #684010, was opened at 2003-02-10 17:42
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=684010&group_id=5470

Category: Library (Lib)
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Michal Vitecek (fufsource)
Assigned to: Nobody/Anonymous (nobody)
Summary: extending dict functionality

Initial Comment:
attached is a simple patch that adds three new methods
to the builtin dictionary object:

1) randkey() -- returns a random key from the dictionary

2) randvalue() -- returns a random value from the
dictionary

3) popranditem() -- returns a random pair (key, value)
and removes it from the dictionary

methods 1&2 are useful because currently getting a
random value off a dictionary is a pain (need to create
a list or either keys or values and then choose a
random bit from it).

method 3 is provided as a supplement for method
popitem() which (based on the used hashed function)
returns the items in almost sequential order _and_
starts from the very start if a new item is added to
the dictionary.

i find all the methods useful because there's no need
to create a temporary list of keys or values or pairs
in cases where dictionary must be used for speedy data
hashing but some features of a list/tuple are needed
(random element access).

with those methods random.choice() could be fixed so it
worked on dictionaries as well.

documentation and UserDict.py are modified as well.

thank you for consideration,

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

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