473,394 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Equivalent of std::set

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

Jul 18 '05 #1
2 5074
Nicolas Fleury 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


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

anton.

Jul 18 '05 #2
On Fri, 26 Sep 2003 10:07:20 -0400, Nicolas Fleury
<ni******@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
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: ma740988 | last post by:
The position returned via the STL std::set container never made much sense to me. When you insert elements within the container, the position returned - via find - does not reflect the actual...
11
by: snnn | last post by:
On the book <Generic Programming and the STL>( Matthew . H . Austern ),this function is defined as iterator set::begin() const. However, why should a const object returns a non-const iterator?...
5
by: Peter Jansson | last post by:
Hello, I have the following code: std::map<int,std::set<std::string> > k; k="1234567890"; k="2345678901"; //... std::set<std::string> myMethod(std::map<int,std::set<std::string> > k)...
10
by: danibe | last post by:
I never had any problems storing pointers in STL containers such std::vector and std::map. The benefit of storing pointers instead of the objects themselves is mainly saving memory resources and...
16
by: Cory Nelson | last post by:
Does anyone know how std::set prevents duplicates using only std::less? I've tried looking through a couple of the STL implementations and their code is pretty unreadable (to allow for different...
2
by: shuisheng | last post by:
Dear All, std::set is sorted. So I am wondering is there any fast way to access (sucn as random access) to its elements just like std::vector. Assume I have a set std::set<inta; So I can...
7
by: Renzr | last post by:
I have a problem about the std::set<>iterator. After finding a term in the std::set<>, i want to know the distance from the current term to the begin(). But i have got a error. Please offer me...
2
by: mathieu | last post by:
hi there, I would like to know if the following piece of code is garantee to work. I am afraid that the cstring address I am using in the std::map found from a request in std::set is not...
2
by: Markus Dehmann | last post by:
I want to derive from std::set, like shown below. But when I try to declare an iterator over the contained elements I get an error, see the twp uncommented lines: #include <set> template<class...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.