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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:42:25+00:00 2026-05-11T14:42:25+00:00

I have a class that acts as an item in a tree: class CItem(

  • 0

I have a class that acts as an item in a tree:

class CItem( list ):   pass 

I have two trees, each with CItem as root, each tree item has some dict members (like item._test = 1). Now i need to compare this trees. I can suggest to overload a comparison operator for CItem:

class CItem( list ):   def __eq__( self, other ):     # first compare items as lists     if not list.__eq__( self, other ): return False     # now compare dict members     if self.__dict__ != other.__dict__: return False     # seems equal     return True 

Now i can compare two trees using ‘==’ or ‘!=’. Is this a ‘pythonic’ way or such comparsion can be done easire?

  • 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. 2026-05-11T14:42:25+00:00Added an answer on May 11, 2026 at 2:42 pm

    My feeling would be something like

    class CItem(list):     def __eq__(self, other):         return list.__eq__(self, other) and self.__dict__ == other.__dict__ 

    but it’s basically the same code you have, just expressed in shorter notation. I can’t think of any more substantial changes to make offhand.

    • 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 acts as a manager and does some work. A
I have a WCF webservice that acts as a data provider for my ASP.NET
I have a datagrid buttoncolumn which acts as delete buttons for my xml nodes.
I have a problem when setting a variable inside a Java class Here is
I have a function that uses Randomized numbers to generate its output. I'd like
I would like to create a base class that will be inherited by other
In an iPad app im using a thirdParty cpp file that acts as a
I'm new to F# and am wondering how I would go about flattening a
Recently in an attempt to integrate a phone with a wireless sensor network i
My Rails 2 app displays a slideshow of photos from Flickr via the flickraw

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.