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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:37:42+00:00 2026-05-26T15:37:42+00:00

I have an class definition with a __hash__ function that uses the object properties

  • 0

I have an class definition with a __hash__ function that uses the object properties to create a unique key for comparison in python sets.

The hash method looks like this:

def __hash__(self):
return int('%d%s'%(self.id,self.create_key))

In a module responsible for implementing this class, several queries are run that could conceivably construct duplicate instances of this class, and the queue that is created in the function responsible for doing this is a represented as a set to make sure the the dupes can be omitted:

in_set = set()
  out_set = set()
  for inid in inids:
    ps = Perceptron.getwherelinked(inid,self.in_ents)

for p in ps:
  in_set.add(p)


  for poolid in poolids:
  ps = Perceptron.getwherelinked(poolid,self.out_ents)
  for p in ps:
    out_set.add(p)
  return in_set.union(out_set)

(Not sure why the indenting got mangled here)

Somehow, despite calling the union method, I am still getting the two duplicate instances. When printed out (with a str method in the Perceptron class that just calls hash) the two hashes are identical, which theoretically shouldn’t be possible.

set([1630, 1630])

Any guidance 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-05-26T15:37:42+00:00Added an answer on May 26, 2026 at 3:37 pm

    If a class does not define a __cmp__() or __eq__() method it should not define a __hash__() operation either

    source

    Define __eq__().

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

Sidebar

Related Questions

I have a class definition that I've seen other define properties that return collections
Let's say I have an object who's class definition looks like: class Command: foo
Have a class definition that looks something like this class someClass(models.Model): field1 = models.ForeignKey('other_app.field4')
I have a class, lets call it A, and within that class definition I
I have a class definition that looks like this: public class SolrObj { [SolrUniqueKey(id)]
I have a class definition that is part of a class definition. var someObject
I have a local class definition and implementation on a particular ABAP object for
Say I have a class definition: class CustomClass { int member; }; Why is
Anyone knows if is possible to have partial class definition on C++ ? Something
I have the following class definition: template<typename QueueItemT> class QueueBC { protected: QueueBC() {}

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.