Equivalent of std::set

Stephen Horne $$$$$$$$$$$$$$$$$ at $$$$$$$$$$$$$$$$$$$$.co.uk
Fri Sep 26 16:43:41 CEST 2003


On Fri, 26 Sep 2003 10:07:20 -0400, Nicolas Fleury
<nid_oizo at yahoo.com_remove_the_> wrote:

>Hi,
>
>I haven't work so much in python and I was wondering what python 
>programmers use for string collections, like an equivalent of C++ 
>std::set.  Do you use a dictionary with dummy values?  Tuple/list?  Is 
>there any other structure in some module with uniqueness ensured and 
>lookup optimised?  I'm only interested in storing strings in that structure.
>
>Thx for help
>
>Nicolas

A set type was introduced in Python 2.3...

http://www.python.org/doc/2.3/whatsnew/whatsnew23.html

http://www.python.org/doc/2.3/lib/module-sets.html

There are other ways, depending on what you are doing with the
strings, though.

For instance, although you can iterate a set, the iteration will not
necessarily be in order (I assume it uses hashing internally, probably
by using a dictionary internally). If you need to access the strings
in order (and there aren't too many of them) you can keep the items in
a sorted list, in which case the bisect module will probably be a big
help.


-- 
Steve Horne

steve at ninereeds dot fsnet dot co dot uk




More information about the Python-list mailing list