Python Forum
does python have a c++ set equivalent container
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
does python have a c++ set equivalent container
#1
Hi,
I come from c++ to python world recently, and am looking for c++ set (basically a balance/red-black tree structure, i think) equivalent container, but I can't find any. I did a quick google, and the closest I could get is bisect + List, which can have O(logN) search time, but can't achieve the O(logN) for insert/delete.

My question: is there such a standard container/Data struct? If not, how people typically get around?

One strong feeling I have, since I come from c++, is that python can do quite a lot of things easily (easier than c++), but most probably not as efficiently. Trying to find a c++ set equivalent in Python is one example to address this feeling.

Thank you!
--Karl
Reply
#2
Python has a built in set type, which I think is basically a hash table. Otherwise you can explore packages such as sortedcollections.
Reply
#3
@Larz60+, I think this answer was intended for some other thread.
Larz60+ likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
buran,
You're correct, now to find the right thread.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020