Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

d3mon95's blog

By d3mon95, history, 8 years ago, In English

hey codeforcers, i decided to do something new and decide to learn python so i need some help here. How can i use an equivalent to c++ set stl in python and similarly how can i use an equivalent to c++ map stl , the dict and set() are not sorted, plz help me.It would be great if someone could provide a usful link or something so that i can learn those things.

  • Vote: I like it
  • +15
  • Vote: I do not like it

| Write comment?
»
8 years ago, # |
  Vote: I like it +20 Vote: I do not like it

std::set and std::map and their multi versions can be provided by copy/pasting this: https://bitbucket.org/mozman/bintrees/src/e90631d7139c910394ae3f8f620246a8a9a93fdf/bintrees/rbtree.py?at=default&fileviewer=file-view-default (This comes from the python bintrees library)
std::unordered_set -> set
std::unordered_map -> map
std::bitset -> no good implementations that I know of; the bitset library doesn't support a bunch of operators and python doesn't have unsigned ints. Using a regular int might work if you're really careful (They're arbitrarily large).
std::vector -> list lol
std::deque and std::queue -> collections.deque
std::priority_queue -> heapq

  • »
    »
    8 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Unfortunately, getting std::set/std::map is not as easy as just copying and pasting the source code by the link above as it imports also abctree.py and treeslice.py. Their total length is 1100+ lines of code.