why i cannot use intersection with position list
hi guys, i try to find a intersection set of two position lists
so i write a code in python, and i have two lists, such as :
position1 = Point()
position1.x =1
position2 = Point()
position2.x=2
a = [copy.deepcopy(position1),copy.deepcopy(position2)]
b = [copy.deepcopy(position1)]
then, when i try to get intersection of those two list a and b
it return me an answer: set([])
that's ridiculous,
normally i should have an answer like: set(a).intersection(set(b)) = set([position1])
if anyone could help me to fix this problem?
it's great thankful for viewing this problem
and i appreciate for your watching and answering.
thanks in advance.
Asked by DinnerHowe on 2016-09-06 04:55:59 UTC
Answers
hi, guys i figure it out ... in ros when we initial the parameters, like position2 = Point() and deepcopy, the hash value is change. however, intersection method compare both hash value and it's value, so what we can do is build a new class just compare value without hash value. OR the other method is rebuild the hash value by yourself, such as Ninja Puppy's suggestion:
class NewPoint(Point):
def __hash__(self):
return hash(self.x) # maybe self.y as well?
Asked by DinnerHowe on 2016-09-07 01:28:01 UTC
Comments