A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2009-April/088181.html below:

[Python-Dev] Getting values stored inside sets

[Python-Dev] Getting values stored inside sets [Python-Dev] Getting values stored inside setsLeif Walsh leif.walsh at gmail.com
Sat Apr 4 01:18:22 CEST 2009
On Fri, Apr 3, 2009 at 8:07 AM, Hrvoje Niksic <hrvoje.niksic at avl.com> wrote:
> But I can't seem to find a way to retrieve the element corresponding to
> 'foo', at least not without iterating over the entire set.  Is this an
> oversight or an intentional feature?  Or am I just missing an obvious way to
> do this?

>>> query_obj in s
True
>>> s_prime = s.copy()
>>> s_prime.discard(query_obj)
>>> x = s.difference(s_prime).pop()

Pretty ugly, but I think it only uses a shallow copy, and it might be
a bit better than iterating, if difference is intelligent.  I haven't
run any tests though.

-- 
Cheers,
Leif
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4