Блог пользователя d3mon95

Автор d3mon95, история, 8 лет назад, По-английски

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.

  • Проголосовать: нравится
  • +15
  • Проголосовать: не нравится

»
8 лет назад, # |
  Проголосовать: нравится +20 Проголосовать: не нравится

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 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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.