Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Set data structure..

0 views
Skip to first unread message

Alessio Pace

unread,
Feb 19, 2003, 8:44:28 AM2/19/03
to
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!

Lexy Zhitenev

unread,
Feb 19, 2003, 9:02:23 AM2/19/03
to

"Alessio Pace" <pucc...@yahoo.it> wrote:
news:uSL4a.20711$uA5.5...@tornado.fastwebnet.it...

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.


Gerrit Holl

unread,
Feb 19, 2003, 9:24:34 AM2/19/03
to
Alessio Pace schreef op woensdag 19 februari om 14:47:07 +0000:

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

unread,
Feb 19, 2003, 12:15:55 PM2/19/03
to
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! :-)

0 new messages