[New-bugs-announce] [issue7212] Retrieve an arbitrary element from a set without removing it

Willi Richert report at bugs.python.org
Mon Oct 26 22:07:19 CET 2009


New submission from Willi Richert <w.richert at gmx.net>:

Sometimes, a non-removing pop() is needed. In current Python versions,
it can achieved by one of the following ways:

1. 
x = some_set.pop()
some_set.add(x)

2. 
for x in some_set: 
        break

3.
x = iter(some_set).next()

More native and clean would, however, be 
some_set.get()

The attached patch does this for set(). If this is accepted by the
community, frozenset should be extended as well.

----------
components: Library (Lib)
files: setobject_get.patch
keywords: patch
messages: 94508
nosy: wrichert
severity: normal
status: open
title: Retrieve an arbitrary element from a set without removing it
type: feature request
versions: Python 3.1, Python 3.2
Added file: http://bugs.python.org/file15207/setobject_get.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7212>
_______________________________________


More information about the New-bugs-announce mailing list