Equivalent of std::set

N

Nicolas Fleury

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

anton muhin

Nicolas said:
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

Python 2.3 introduced Set type, in the former versions common idiom was
to use dictionaries with dummies IMHO.

anton.
 
S

Stephen Horne

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top