Python Forum
looking for a multi item container
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
looking for a multi item container
#1
this would be quite easy to implement; perhaps easier than the effort to find an existing one (since i am not very good at the latter), perhaps already in Python under some name not obvious to me. what i need soon is a mapping which lets me insert duplicate entries under the same key and maintains order of insertion within the same key. it also needs to be able to provide items in that order after a search for that key as opposed just doing so via an iteration from the beginning. IoW, it needs to be able to move the current position forward or backward based on a given key being searched.
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
If i understand the requirements correctly, you could use a defaultdict with its values in a deque
import collections

container = collections.defaultdict(collections.deque)

container['one'].append(1)
container['one'].append(1)
container['one'].append(2)
container['one'].append(3)
container['one'].append(2)

print(container['one'])

container['one'].rotate(1)

print(container['one'])

container['one'].rotate(-2)

print(container['one'])
Output:
deque([1, 1, 2, 3, 2]) deque([2, 1, 1, 2, 3]) deque([1, 2, 3, 2, 1])
Reply
#3
i was going to implement my own with a dict and each item being a list. it would all be inside something where i can keep a current key and index. i implemented this in C ages ago as a binary tree and it made lots of things so much easier. sometimes i wonder what life would be like if i went back to C. would i implement pythonic-like things such as generators and iterators?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  UnUnloading values from multiple widgets in a container UGuntupalli 3 587 Apr-20-2020, 08:53 PM
Last Post: UGuntupalli
  How do I install Python 3.8.1 in a RHEL 8 UBI container? DevLinuxNC 1 587 Jan-08-2020, 09:37 PM
Last Post: Clunk_Head
  testing if this is a container type Skaperen 7 1,006 Jan-25-2019, 07:12 AM
Last Post: buran

Forum Jump:

User Panel Messages

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