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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:38:21+00:00 2026-05-17T02:38:21+00:00

I have a Ring structure implemented as follows (based on a cookbook recipe I

  • 0

I have a Ring structure implemented as follows (based on a cookbook recipe I found):

class Ring(list):

    def turn(self):
        last = self.pop(0)
        self.append(last)

    def setTop(self, objectReference):
        if objectReference not in self:
            raise ValueError, "object is not in ring"

        while self[0] is not objectReference:
            self.turn()

Say I do the following:

x = Ring([1,2,3,4,4])
x.setTop(4)

My code will always set the first 4 (currently x[3]) to x[0]. It seems (via object identity and hash id testing between x[3] and x[4]) that Python is reusing the 4 object.

How do I tell Python that I really want the second 4 (currently x[4]) to be at the top?

Apologies for the basic question … one of the downfalls of being a self-taught beginner.

Thanks,

Mike

===EDIT===

For what it’s worth, I dropped the setTop method from the class. I had added it to the standard recipe thinking “hey, this would be neat and might be useful.” As the answers (esp. “what’s the difference”, which is spot on) and my own experience using the structure show, it’s a crappy method that doesn’t support any of my use cases.

In other words, adding something because I could instead of fulfilling a need = fail.

  • 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-17T02:38:22+00:00Added an answer on May 17, 2026 at 2:38 am

    From Learning Python, 4th edition — Chapter 6:

    At least conceptually, each time you generate a new value in your script by running an
    expression, Python creates a new object (i.e., a chunk of memory) to represent that
    value. Internally, as an optimization, Python caches and reuses certain kinds of un-
    changeable objects, such as small integers and strings (each 0 is not really a new piece
    of memory—more on this caching behavior later). But, from a logical perspective, it
    works as though each expression’s result value is a distinct object and each object is a
    distinct piece of memory.

    The question is..

    if x[3] is x[4]:
        print "What's the difference?"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have NSMutableArray named *arrWords containing list of 50 words. e.g. Bond/Bind/King/Sing/Ring etc. I
I have the following routes definition: (require '[compojure.core :as ccore] '[ring.util.response :as response]) (def
I have a clojure/ring project that has two distinct app/handlers running on different ports
I have a security number generator device, small enough to go on a key-ring,
I have been trying to draw an annulus (ring with thickness) with a transparent
I'm trying to force SSL on my site. I want to have a ring
I'm trying to simulate a token ring using python with sockets, but I have
I have the following shape XML: <?xml version=1.0 encoding=utf-8?> <shape xmlns:a=http://schemas.android.com/apk/res/android a:shape=ring a:innerRadiusRatio=3 a:thicknessRatio=8
I have the next code with some thumbnails: <div class=gallery-wrap> <div class=gallery galleryid-45 id=gallery-1>
I have a data type Polynomial r for polynomials in Haskell and a Ring

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.