Set data structure..

Alessio Pace puccio_13 at yahoo.it
Wed Feb 19 12:15:55 EST 2003


Gerrit Holl wrote:

> 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! :-)




More information about the Python-list mailing list