Python Forum
an object i would like to have
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
an object i would like to have
#1
i would like to have an object that operates like a set but iterates its contents in sorted order.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
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
buran likes this post
Reply
#3
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
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>
Gribouillis write Jun-09-2023, 09:15 AM:
Off site promotion link removed. Please read What to NOT include in a post
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020