Python Forum
an object i would like to have - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: an object i would like to have (/thread-40010.html)



an object i would like to have - Skaperen - May-18-2023

i would like to have an object that operates like a set but iterates its contents in sorted order.


RE: an object i would like to have - snippsat - May-18-2023

Python Sorted Containers
>>> from sortedcontainers import SortedSet
>>> 
>>> lst = ['car', 'taxi', 'car', 'bus', 'taxi', 'car', 'train']
>>> ss = SortedSet(lst)
>>> for item in ss:
...     print(item)
...     
bus
car
taxi
train



RE: an object i would like to have - Skaperen - May-20-2023

i should have also said i want the fetch-one-next-item timing to be the same as or close that for plain set(). sorting the entire set and returning the first from that result is timing i want to avoid. i implemented this kind of thing in C many years ago and it has served me well for almost every container/dictionary usage over the years of coding in C. it worked like a set but allowed each item to be assigned a value. i could search for a given key from the front or the back. multiple items with the same key were allowed (and could be assigned different values). once found, the "next key" could be requested. the group of like keys were kept in the order inserted, and a "next by next" scan would step through them in that order. a "previous by previous" scan would get them in reverse order. it was implemented as an AVL binary tree and outperformed a hash up to a size around 1,200,000.


RE: an object i would like to have - Iusullin4235 - Jun-09-2023

I think it's trilingual. Because a person who speaks two languages is often called bilingual. The way people usually talk for fun is byelingual because they lose a little bit of each language.
<url snipped>