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 8044733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:19:06+00:00 2026-06-05T05:19:06+00:00

Some background of the data : some different games are being played, and each

  • 0

Some background of the data: some different games are being played, and each of them hosts a number of players. Each game consists of a number of rounds, and during each round each player involved makes an action. What I am trying to do here is to construct a data structure in memory for storing the complete history of individual actions taken by the players across all the games being played.

An obvious structure is a deeply nested dictionary/hashmap, where each game_id is mapped to a number of player_ids, and each player_id is mapped to different round_numbers, and each round_number is mapped to an action.

In other words, game_id:player_id:round_number:action. On the other hand, I can also use game_id:round_number:player_id:action

Problem arises when I try to access the data structures above for different analytical purposes. For example, it’s inconvenient to have game_id:player_id:round_number:action, if I want to know all the actions made by players in a particular round of a given game. Conversely, it is equally inconvenient to have game_id:round_number:player_id:action, if I want to know all the actions made by a particular player during the course of a given game. Unfortunately, in my case, I need to ask both those questions frequently.

I wonder if there is a single data structure which can store such data and is convenient for accessing both player-level and round-level data as described above. The implementation will be in Python, if that matters.

EDIT: a few people have recommended in-memory sqlite database to handle such relational queries. However, its performance may be an issue for me, as discussed here: SQLite Performance Benchmark — why is :memory: so slow…only 1.5X as fast as disk?

  • 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-05T05:19:08+00:00Added an answer on June 5, 2026 at 5:19 am

    One way would be to store the data in a dict, but maintain indexes to allow quick access to various views into your data. You could structure this with a class, or just functions. Here is the jist of it (untested):

    from collections import defaultdict
    
    game_dict = {}  # keyed by (game, player, round) tuple
    game_player_ix = defaultdict(list)
    game_round_ix = defaultdict(list)
    
    def add_action(game, player, round):
        game_dict[(game, round, player)] = action # track the action in the main dict
        game_player_ix[(game, player)].append(round)  # keep an index for lookups by player
        game_round_ix[(game, round)].append(player) # another index for lookups by round
    
    def get_all_player_actions(game, player):
        return (game_dict[(game,player,round)] for round in game_round_ix[(game, player)]) # iterator
    
    def get_all_round_actions(game, round):
        return (game_dict[(game,player,round)] for player in game_player_ix[(game, round)]) # iterator
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just some background, sorry so long winded. I'm using the System.Data.SQLite ADO.net adapter to
Background : I've inherited some MATLAB code to analyze data for my Ph.D. research.
Background: Our web app uses the jquery.constrain.js plugin to handle data entry in some
I have a gridview with some data bound to it. I also have different
I use a third party control which exports some data to different formats. The
I have a DataGridView where the background of each row is different depending on
On Iphone App start I start a background thread to receive some data from
Some Background I have an iPhone app with three UIWebViews, each used to show
Some background: I am having an issue with one part of my program where
Some background, I've been designing a user profile for our Django database system and

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.