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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:28:47+00:00 2026-06-07T12:28:47+00:00

I am creating a doubly linked structure and am having some issues with comparing

  • 0

I am creating a doubly linked structure and am having some issues with comparing if two nodes are equal. The structure is fairly complex in that it has multiple attributes including name, row, column, right, left, up, and down. If two nodes are equal they must agree on all of these attributes. I know in my eq method I could simply hard code checking each attribute versus the other but I figured there would be an easier way to do it and found a way that works most of the time. Thus I have the following:

def __init__ (self,row,col,name=None,up=None,down=None,left=None,right=None):
    self.name  = name
    self.row   = row
    self.col   = col
    self.up    = up
    self.down  = down
    self.left  = left
    self.right = right

def __eq__ (self, other):
    return vars(self) == vars(other)

And various other methods that aren’t really important to this. So my shortcut for determining whether two Nodes was to basically look at the dictionary of their variables and let python compare the two dictionaries for equivalence.

This works great! As long as the two nodes are actually equal. It returns True and I go on my merry way with my code. BUT if the two nodes are actually not equal it falls apart. I get

File "*filename*", line 35 in __eq__ return vars(self) == vars(self) 

written to the screen numerous amounts of times until it finally says

RuntimeError: maximum recursion depth exceeded

I know there are some ways around this, i.e. I could explicitly check each attribute, but that’s lame and I want to know why this isn’t working, and if it can be easily fixed. I have tested this method with other simpler dictionaries and it works so my thought is that the issue has something to do with determining if objects are equal but I have no idea what I could do here. I realize I could also just do a error catch and then make that return False but something other than those two solutions would be appreciated,

  • 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-07T12:28:48+00:00Added an answer on June 7, 2026 at 12:28 pm

    It looks like your up, down, etc are pointing to other instances of your class.

    Your comparison code is basically saying, to test if self == other, does self.up == other.up? does self.up.up == other.up.up? etc. And then recursing until it runs out of space.

    You may instead want to use

    def __eq__(self, other):
        return self.name == other.name \
            and self.row == other.row \
            and self.col == other.col \
            and self.up is other.up \
            and self.down is other.down \
            and self.left is other.left \
            and self.right is other.right
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a media player (mostly video but with some graphical interfaces) that has
I am creating some doubly linked list of type Double and no matter how
I'm having a problem with a doubly linked list so I have two questions.
I'm currently creating a circular doubly-linked list as exercise. The exercise is templating the
I am creating an Abstract Data Type, which create a doubly linked list (not
I'm creating an application that has a Gallery , and this Gallery has a
Im creating my own doubly linked list program (I know there is a list
I'm in the process of creating a FIFO implemented as a doubly-linked list, but
I am creating a program that filters the contents of a JTable using two
I'm creating a doubly-linked list in Objective-C. I would like my node class to

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.