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
  uploading files from a ubuntu local directory to Minio storage container dchilambo 0 398 Dec-22-2023, 07:17 AM
Last Post: dchilambo
  Upload Files to Azure Storage Container phillyfa 6 578 Dec-22-2023, 06:11 AM
Last Post: Pedroski55
Lightbulb shutdown host from docker container cosmin1805 0 914 Nov-27-2022, 06:34 PM
Last Post: cosmin1805
  networkx package is not visible in singularity container image erdemath 11 2,180 Oct-14-2022, 12:04 PM
Last Post: Larz60+
  python installation/running inside singularity container erdemath 2 1,689 Sep-21-2022, 08:13 AM
Last Post: erdemath
  Python in Singularity Container on Ubuntu erdemath 0 876 Aug-31-2022, 02:17 PM
Last Post: erdemath
  Can I check multi condition for 1 item in a easy way? korenron 4 1,536 May-01-2022, 12:43 PM
Last Post: deanhystad
  Remove an item from a list contained in another item in python CompleteNewb 19 5,547 Nov-11-2021, 06:43 AM
Last Post: Gribouillis
  UnUnloading values from multiple widgets in a container UGuntupalli 3 2,694 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 3,521 Jan-08-2020, 09:37 PM
Last Post: Clunk_Head

Forum Jump:

User Panel Messages

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