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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:47:48+00:00 2026-06-09T16:47:48+00:00

I have a class that stores a list of lists in a matrix style,

  • 0

I have a class that stores a list of lists in a matrix style, and it can just be indexed like [x,y].

Right now I have these set:

test_dict = {1:"cow",2:"horse"}

randommap = mapArray(None, (20,20))

random map is just filled with lists of 1s. So any index will return a 1. But here is where I get lost, maybe because of a misunderstanding about how dictionaries work:

test_dict[1]

That obviously gives back “cow”
and

randommap[1,1] #or any two x,y values up to 20 for that matter

gives me a value of 1.

But how come this gives me a key error:

test_dict[randommap[1,1]]

In isolation, indexing randommap there gives me a value of 1, so shouldn’t that 1 be supplied as an index for test_dict, thus returning me “cow”?

Update:
These are the two methods I presume are causing the issue. It appears that they are returning strings instead of integers, but I don’t know If I quite understand the difference between the two.

def __str__(self):
    return str(self.mapdata)

def __repr__(self):
    return str(self.mapdata)

Here is the overloaded __getitem__ method:

def __getitem__(self, (x,y)):
    #Just reverses it so it works intuitively and the array is 
    # indexed simply like map[x,y] instead of map[y][x]
    return mapArray(self.mapdata[y][x])

Sorry the formatting seems to have been messed up a bit.

  • 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-09T16:47:50+00:00Added an answer on June 9, 2026 at 4:47 pm

    Given the updated question, it seems that __getitem__ returns a new mapArray.

    I think your overloaded __getitem__ should be something like

    def __getitem__(self, (x,y)):
        return self.mapdata[y][x] 
    

    instead, (assuming that the [y][x] order is intentional).

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

Sidebar

Related Questions

I have a class that stores all created references in a static list like
I have a linked list class that stores a linked collection of entities. I've
I have a class that stores a list of dictionary entries. I want bind
I have a class that looks like this: typedef std::list<char*> PtrList; class Foo {
I have a class object that stores some properties that are lists of other
I have a class that stores paths to CSS and Javascript files in arrays.
I have a PHP class that stores a complex multidimensional array, and rather than
I have a class that basically stores files in amazon s3. Here is what
I have a logging class that stores entries in a datatable dt. I then
I have class and I want to initalize column that stores pictuer with type

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.