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

  • Home
  • SEARCH
  • 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 9184979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:11:03+00:00 2026-06-17T19:11:03+00:00

So I currently have a 2d list of objects that define the map of

  • 0

So I currently have a 2d list of objects that define the map of a game where each object represents a tile on that map. As I was repurposing the code for something else, I wondered if it would make more sense to use a dictionary to store the map data or to continue using a list. With a list, the indices represent the x and y of the map, whereas in a dictionary, a (x,y) tuple would be the keys for the dictionary.

The reason I ask is because the map changing is a rare event, so the data is fairly static, and as far as i know, the fairly constant lookups will be faster in dictionaries. It should also simplify looping through the map to draw it. Mostly I think using dictionaries will simplify accessing the data, though I’m not sure that will be the case in all cases.

Are these benefits worth the additional memory that I assume the dictionary will take up? or am I even right about the benefits being benefits?

EDIT
I know that the current method works, its was moreso to whether or not it would make sense to switch in order to have cleaner looking code and to find any potential drawbacks.
Stuff like looping through the array would go from something like

for i in range(size[0]):
    for e in range(size[1]):
        thing.blit(....using i and e)

to

for i, e in dict.items():
    i.blit(....using i and e)

or looking up a dict item would be

def get(x, y):
    if (x in range(size[0])) and (y in range(size[1])):
        return self.map[x][y].tile

to

def get(item):
    return self.dict.get(item)

its not much, but its somewhat cleaner, and if its not any slower and there are no other drawbacks i see no reason not to.

  • 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-17T19:11:05+00:00Added an answer on June 17, 2026 at 7:11 pm

    I would be wary of premature optimization.

    Does your current approach have unacceptable performance? Does the data structure you’re using make it harder to reason about or write your code?

    If there isn’t a specific problem you need to solve that can’t be addressed with your current architecture, I would be wary about changing it.

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

Sidebar

Related Questions

I have a social-clique-object. In each social-clique-object I have a list of friend-objects. Each
I have a ComboBox with a list of objects bound to it. Currently i
Currently I have the follow ps that reads a list of user names and
Assuming I have a list of objects that have the following fields parent value
Currently in MVC, we have to define columns manually whenever we want to list
I have a class that contains a list of objects. I previously had this
I have a list of objects that contain a start/end date. I am trying
I currently have a list of DateTimes stored as the timezone's UTC datetime. When
I currently have a list of things to update in the given mysqli query:
I am working with a small theatre company. Currently they have a list of

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.