[Python-Dev] Getting values stored inside sets (original) (raw)
Leif Walsh leif.walsh at gmail.com
Sat Apr 4 01🔞22 CEST 2009
- Previous message: [Python-Dev] Getting values stored inside sets
- Next message: [Python-Dev] Summary of Python tracker Issues
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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?
queryobj in s True sprime = s.copy() sprime.discard(queryobj) x = s.difference(sprime).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
- Previous message: [Python-Dev] Getting values stored inside sets
- Next message: [Python-Dev] Summary of Python tracker Issues
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]