ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

why i cannot use intersection with position list [closed]

asked 2016-09-06 04:55:59 -0500

DinnerHowe gravatar image

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.

edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by DinnerHowe
close date 2016-09-22 22:30:32.781430

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-09-07 01:28:01 -0500

DinnerHowe gravatar image

updated 2016-09-07 01:28:47 -0500

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?
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-09-06 04:55:59 -0500

Seen: 85 times

Last updated: Sep 07 '16