I can't think of specialized Set classes, but I don't think that you're
gonna use very large sets. Then, the dictionaries is what you might wish.
The lookup of the keys is far faster than from lists.
Lexy.
As of Python 2.3, you can do:
18 >>> import sets
19 >>> myset = sets.Set(string.lowercase)
20 >>> myset
Set(['a', 'c', 'b', 'e', 'd', 'g', 'f', 'i', 'h', 'k', 'j', 'm', 'l', 'o', 'n', 'q', 'p', 's', 'r', 'u', 't', 'w', 'v', 'y', 'x', 'z'])
See also:
http://www.python.org/doc/2.3a1/whatsnew/node2.html
http://www.python.org/peps/pep-0218.html
http://www.python.org/dev/doc/devel/lib/module-sets.html
yours,
Gerrit.
--
Asperger Syndroom - een persoonlijke benadering:
http://people.nl.linux.org/~gerrit/
Het zijn tijden om je zelf met politiek te bemoeien:
http://www.sp.nl/
> Alessio Pace schreef op woensdag 19 februari om 14:47:07 +0000:
>> Hi, I am a python newbie, so this could be a silly question:
>> I need a Set like data structure, I just see list and dictionary as
>> built-in. Should I use one of those for my set purpose(I was thinking
>> about using a dictionary giving meaning only to the keys, but it seems a
>> waste of space for large inputs) and if so, which one has better access
>> performance to check if an element is in the set? Thanks!
>
> As of Python 2.3, you can do:
> 18 >>> import sets
> 19 >>> myset = sets.Set(string.lowercase)
> 20 >>> myset
> Set(['a', 'c', 'b', 'e', 'd', 'g', 'f', 'i', 'h', 'k', 'j', 'm', 'l', 'o',
> 'n', 'q', 'p', 's', 'r', 'u', 't', 'w', 'v', 'y', 'x', 'z'])
>
> See also:
> http://www.python.org/doc/2.3a1/whatsnew/node2.html
> http://www.python.org/peps/pep-0218.html
> http://www.python.org/dev/doc/devel/lib/module-sets.html
>
> yours,
> Gerrit.
>
Thanks a lot! :-)