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

"Martin v. Löwis" martin at v.loewis.de
Thu Nov 5 22:21:01 CET 2009


>    I feel pretty strongly that it's a wart in the language, and a
> sufficiently strong one that it should be remedied.  I'm happy to
> champion it, but haven't the faintest idea what that entails.

There are two ways

a) write a library that provides what you want, publish it on PyPI,
   and report back in a few years of how many users your library has,
   what they use it for, and why it should become builtin
b) write a PEP, wait a few years for the language moratorium to be
   lifted, provide an implementation, and put the PEP for pronouncement.
   Careful reading of the Moratorium PEP may allow shortening of the
   wait.

In any case, it seems that this specific change will see some
opposition. So you will need to convince the opposition, one way or
the other.

>    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.

If you chose to write a PEP, include a proof that this approach is
indeed horrible in terms of efficiency; I question that.

Regards,
Martin


More information about the Python-Dev mailing list