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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:17:32+00:00 2026-05-26T12:17:32+00:00

Can someone explain to me how the funcion list.index() functions? I have the following

  • 0

Can someone explain to me how the funcion list.index() functions? I have the following code:

def getPos(self,tile):
        print self.tiles[5][5]
        print tile
        try:
           myIndex = self.tiles.index(tile)
           #some code
        except:
           print "exception raised"
           #some code

The result:

<Tile.Tile instance at 0x36BCEB8>
<Tile.Tile instance at 0x36BCEB8>
exception raised

Do you have an idea why list.index() returns an exception although the tile variable is a reference to an element of tiles[][] ? Thanks a lot.

ps: btw I’m passing tiles[5][5] in this specific case

  • 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-05-26T12:17:32+00:00Added an answer on May 26, 2026 at 12:17 pm

    While the element does exist, it is not directly a member of tiles:

    • tiles is a two-dimensional list (a list of lists).
    • tiles[5] is a list of Tiles.
    • tiles[5][5] is a single Tile.

    Python does not recursively descend into a multidimensional list to find the element you’re looking for. Therefore tiles.index(tile) fails; tiles[5].index(tile) would work.

    To illustrate:

    >>> l = [[1,2], [3,4]]
    >>> l.index(4)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: 4 is not in list
    >>> l[1].index(4)
    1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone explain the structure of reduce() in the following example: def f2(list): return
In the following jquery function, can someone explain to me why second is being
I am newbie to jQuery, can someone explain what this code does: $(#currency form).submit(function(e)
Can someone explain to me what this code does? dojo[(show ? remove : add)
Can someone explain the following behavior? Specifically, why does the function return a different
Can someone please explain the following. I've scoured the net for ages trying to
Referring to this Python List Comprehension Vs. Map question, can someone explain why List
Can someone explain to me why I cannot use document.getElementById('id').value inside of a function?
can someone explain me why this script is not working? <script type=text/javascript> function destroy(ID)
Can someone visually explain what's going on here please. var stack = []; function

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.