Set data structure..

Gerrit Holl gerrit at
Wed Feb 19 15:24:34 CET 2003

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:


Asperger Syndroom - een persoonlijke benadering:
Het zijn tijden om je zelf met politiek te bemoeien:

More information about the Python-list mailing list