Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7894205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:20:06+00:00 2026-06-03T07:20:06+00:00

How should I implement very fast lookups of items in a collection? class Person(object):

  • 0

How should I implement very fast lookups of items in a collection?

class Person(object):
    __all__ = dict()

    def __init__(self, _id, name, age):
        self._id = _id
        self.name = name
        self.age = age
        self.__class__.__all__[_id] = self

Suppose I wish to get the five oldest people. If len(Person.__all__) is quite large, and I need to do this operation frequently, what is the best practice? Currently my code takes about 4hrs to run, and I haven’t even fed the whole dataset in yet.

My current thinking is that I could use a database to maintain indexes, but my feeling is that this would be slower than keeping all objects in ram. (I can comfortably fit every object in ram).

Or, I could have some sort of index based on an auto-sorted list, within Python. So, when I needed to look up people of a certain age, I would query that list, to find ids, then use Person.__all__ to get the object itself.

What would be the best option?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:20:08+00:00Added an answer on June 3, 2026 at 7:20 am

    You can make an in memory database with sqlite. It’s easy to move the db to disk later on if you need to

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement a derived class that should also implement an interface, that
My project is a computer vision java application which should implement the following :
I have an interface for a variety of classes, all of which should implement
I need a C# library to deal with matrices. It should implement singular value
Should I implement named parameters in Java using Hash tables? I saw this entry:
What single aspect of agile development should we implement first to improve our development
Can anyone give an idea of how should I implement undo/redo of cutting/copying/pasting of
What is the best practice? How should I implement it so that the database
How should I properly implement data access in my custom model binders? Like in
When I want to implement ViewModel I should cut everything c# code from my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.