Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Equivalent of std::set

Reply
Thread Tools

Equivalent of std::set

 
 
Nicolas Fleury
Guest
Posts: n/a
 
      09-26-2003
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

 
Reply With Quote
 
 
 
 
anton muhin
Guest
Posts: n/a
 
      09-26-2003
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.

 
Reply With Quote
 
 
 
 
Stephen Horne
Guest
Posts: n/a
 
      09-26-2003
On Fri, 26 Sep 2003 10:07:20 -0400, Nicolas Fleury
<(E-Mail Removed)_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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Warning:Xst:382 - Register A is equivalent to B mag VHDL 1 05-19-2005 05:10 PM
instancename of current entity/architecture -- equivalent to C++ this??? Eric Peers VHDL 2 11-18-2004 05:23 PM
VHDL equivalent of verilog trireg Sanjeev VHDL 4 07-23-2004 09:55 AM
equivalent types in different packages Lolo VHDL 3 09-22-2003 03:23 PM
Re: Image Scanning - TWAIN equivalent Brendan Duffy ASP .Net 0 07-24-2003 08:29 AM



Advertisments