3

Help for STL equivalents in Python

 2 years ago
source link: http://codeforces.com/blog/entry/106406
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

I recently started learning python , so I was looking for some C++ STL equivalents in Python. is there any way i can achieve a similar functionality of —

Set and Maps in python with —

insert (log n)
delete (log n)
find (log n)

as fas a I Understand Python Standard Sets are not sorted and are implemented using Hash-Tables (similar to unordered-Sets in C++) has —

insert (O(1) average case , Worst case O(n) [when large no of values have same hash value])
delete (O(1) average case , Worst case O(n) [when large no of values have same hash value])
find (O(1) average case , Worst case O(n) [when large no of values have same hash value])

I know there is a third party package called sortedcontainers which has some C++ equivalents —

std::set    sortedcontainers.SortedSet
        std::multiset   sortedcontainers.SortedList
        std::map    sortedcontainers.SortedDict

but I want to get these funcionalities without installing any third party packages (because those would be local to my environment), and I want to submit to codeforces.

can anybody help?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK