There isn't. See Python's standard library - is there a module for balanced binary tree? for a general discussion of the equivalents of C++ tree containers (map
, set
, multimap
, multiset
) in Python.
The closest I can think of is to use a dictionary mapping integers to counts (also integers). However this doesn't get you the keys in order, so you can't search using lower_bound
. An alternative is a to use an ordered list, as suggested by others already, maybe a list of (integer, count) tuples? If you only need to search after you've done all your insertions, you could use the dictionary as a temporary structure for construction, build the list after you've done all the insertions, then use the list for searching.
Counter
class in python: docs.python.org/2/library/collections.html#collections.Counter – GastrotrichCounter
is not an equivalent tostd::multiset
. – Embolismmultiset
seems to have a richer interface than the PythonCounter
. Additionally, the C++multiset
is ordered, so methods likelower_bound
don't have any meaning in Python'sCounter
. Basically, they their use cases overlap somewhat, but they are not the same thing. – Dialyser