[Python-Dev] Retrieve an arbitrary element from a set withoutremoving it

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Nov 4 02:00:12 CET 2009


Antoine Pitrou wrote:
> Guido van Rossum <guido <at> python.org> writes:
> 
>>Picking a random element can be done in O(1) only if the data
>>structure supports access by index, which Python's hash tables don't.
> 
> Well, at the implementation level, they can. You'd just have to pick a new
> random index until it points to a non-empty slot.

But that's hardly O(1).

-- 
Greg


More information about the Python-Dev mailing list