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

geremy condra debatem1 at gmail.com
Fri Nov 6 01:30:05 CET 2009


On Thu, Nov 5, 2009 at 6:17 PM, James Y Knight <foom at fuhm.net> wrote:
> On Nov 5, 2009, at 6:04 PM, geremy condra wrote:
>>
>> Perhaps my test is flawed in some way?
>
> Yes: you're testing the speed of something that makes absolutely no sense to
> do in a tight loop, so *who the heck cares how fast any way of doing it is*!
>
> Is this thread over yet?
>
> James

I'm testing the speed because the claim was made that the pop/add
approach was inefficient. Here's the full quote:

>    The obvious way, for newcomers, of achieving the effect is:
>
>  x = s.pop()
>  s.add(x)
>
> ... and that's simply horrible in terms of efficiency.  So the
> "obvious" way of doing it in Python is wrong(TM), and the "correct"
> way of doing it is obscure and raises misleading exceptions.

Since I use this in a graph theory library that I am currently trying
to scale to handle 300 million node simulations, and this is used in
several relevant algorithms, I was concerned.

Geremy Condra


More information about the Python-Dev mailing list