Equivalent of std::set

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nicolas Fleury

    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

  • anton muhin

    #2
    Re: Equivalent of std::set

    Nicolas Fleury wrote:[color=blue]
    > 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
    >[/color]

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

    anton.

    Comment

    • Stephen Horne

      #3
      Re: Equivalent of std::set

      On Fri, 26 Sep 2003 10:07:20 -0400, Nicolas Fleury
      <nid_oizo@yahoo .com_remove_the _> wrote:
      [color=blue]
      >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[/color]

      A set type was introduced in Python 2.3...



      The official home of the Python Programming Language


      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

      Comment

      Working...