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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:45:28+00:00 2026-05-20T12:45:28+00:00

This may be difficult to explain. I want to specify two indexes, and then

  • 0

This may be difficult to explain. I want to specify two indexes, and then run a for loop. If the current x being checked in the loop is the exact same item specified at the location of the two indexes, then it should return a message.

array = [ [1,1,1,1], [2,2,2,2], [3,3,3,3], [4,4,4,4] ]

Again, here’s my array. I want it to go through the for loop and print the message out when x is the 1 at memory of array[0][0], aka the same piece of memory.

for x in array:
    if x == array[0][0]:
        print "%s is the object you're looking for." % x

Now, why I need it to make sure it is the same exact object in memory is because, this would loop through the following three 1’s in the first list, and return the message too, as they have the same value as the first 1. I do not need this. I need only to match actual points in memory, not values.

  • 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-20T12:45:29+00:00Added an answer on May 20, 2026 at 12:45 pm

    I think what you’re asking is how to test object identity rather than object equality.

    In Python you can do this with the is operator, i.e.

    if x is y:
    

    Rather than:

    if x == y:
    

    However, you’re going have problems with ints and strings because the Python runtime automatically re-uses objects it creates for these from a pool:

    >>> a = 1
    >>> b = 1
    >>> a is b
    True
    >>> id(a),id(b)
    (13561552, 13561552)
    

    I think short strings are automatically “interned” in this way and you can force longer strings to be using the intern() function:

    >>> c = 'Long string'
    >>> d = 'Long string'
    >>> c is d
    False
    >>> c = intern(c)
    >>> d = intern(d)
    >>> c is d
    True
    

    However, it seems the long type isn’t interned so you use that:

    >>> a = 1L
    >>> b = 1L
    >>> a is b
    False
    

    However, object identity for built-in types is down to the implementation of Python rather than being in the language, and is not something you should rely on either way. I think you would be better off creating your own class of objects and writing an appropriate __eq__ method for them, i.e. write your code it works based on object equality rather than identity.

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

Sidebar

Related Questions

this may be a little difficult to explain, but I'll try. I'm creating a
Okay, so this one may be difficult but I will do my best to
This will be a bit difficult to explain but I will try my best.
I am not sure I am going to be able to explain this one
First of all, my question may be unclear. I will try to explain it.
I shall attempt to explain the scenario. I have a gridview I wish to
This is most certainly a language agnostic question and one that has bothered me
I have several projects on my development system - some projects are open source,
I have written a custom server control which (pseudo-code) looks like public class MyCustomCtrl
I am just starting porting an application to ASP.net MVC and I have an

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.