Manipulating MySQL Sets

Carsten Haese carsten.haese at gmail.com
Sun Dec 13 12:10:45 EST 2009


Victor Subervi wrote:
> I need to get at the individual elements of the set (that which is
> between the single quotes).

It's not quite clear what you mean by "get at the individual elements",
so I'll just show you a couple of things you can do to a set, and maybe
one of them comes close to what you need:

>>> from sets import Set
>>> aSet = Set(['Small', 'Extra-small', 'Medium'])

Do something for each element:

>>> for element in aSet:
...     print element
...
Small
Extra-small
Medium

Convert the set to list:

>>> list(aSet)
['Small', 'Extra-small', 'Medium']

Test membership in the set:

>>> 'Small' in aSet
True
>>> 'Banana' in aSet
False

HTH,

--
Carsten Haese
http://informixdb.sourceforge.net




More information about the Python-list mailing list