How to get an item from a simple set?
Pete Forman
pete.forman at westerngeco.com
Wed Nov 24 10:26:55 EST 2004
I have a set that contains one item. What is the best way of getting
at that item? Using pop() empties the set. Here is what I've tried.
Python 2.3.4 (#1, Jun 13 2004, 11:21:03)
[GCC 3.3.1 (cygming special)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from sets import Set
>>> s = Set(['foo'])
>>> s.copy().pop()
'foo'
>>> [x for x in s][0]
'foo'
>>> s[0]
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: unindexable object
--
Pete Forman -./\.- Disclaimer: This post is originated
WesternGeco -./\.- by myself and does not represent
pete.forman at westerngeco.com -./\.- opinion of Schlumberger, Baker
http://petef.port5.com -./\.- Hughes or their divisions.
More information about the Python-list
mailing list