cannot use python intersection set with ROS point lists
<p>i try to find a intersection set of two position lists, in ROS</p>

<p>so i write a code in python, and i have two lists, such as :</p>

<pre><code>position1 = Point()

position1.x =1

position2 = Point()

position2.x=2

a = [copy.deepcopy(position1),copy.deepcopy(position2)]

b = [copy.deepcopy(position1)]
</code></pre>

<p>then, when i try to get intersection of those two list a and b</p>

<p>it return me an answer: set([])</p>

<p>that's ridiculous,</p>

<p>normally i should have an answer like: set(a).intersection(set(b)) = set([position1])</p>

<p>if anyone could help me to fix this problem?</p>

<p>it's great thankful for viewing this problem</p>

<p>and i appreciate for your watching and answering.</p>

<p>thanks in advance.</p>

<p>here is my testing code</p>

<pre><code>import rospy,copy
from geometry_msgs.msg import Point
class test():
 def __init__(self):
  position1 = Point()
  position1.x =1
  position2 = Point()
  position2.x=2
  a = [copy.deepcopy(position1),copy.deepcopy(position2)]
  b = [copy.deepcopy(position1)]
  print  set(a).intersection(set(b))
  print 'a', set(a),'\n'
  print 'b', set(b)

if __name__=='__main__':
 try:
  rospy.loginfo ("initialization system")
  test()
  rospy.loginfo ("process done and quit")
 except rospy.ROSInterruptException:
  rospy.loginfo("robot twist node terminated.")
</code></pre>

<p>BTW,ROS Point type is posted here: <a href="http://docs.ros.org/jade/api/geometry_msgs/html/msg/Point.html" rel="nofollow">http://docs.ros.org/jade/api/geometry_msgs/html/msg/Point.html</a></p>

<p>@Ninja Puppy delete an answer, which i think it helpful as well, so i add it here. while, if this is forbidden or Ninja Puppy feel sick of this, i will delete this answer too. following is his answer</p>

<blockquote>
  <p>Okay, going by your comment:</p>

<pre><code>a[0]==b[0] is true, because they are both position1, but hash(a[0]) and hash(b[0]) is different
</code></pre>
  
  <p>One way is to create a new Point that supports a hash that's
  meaningful for use in a set, eg:</p>

<pre><code>class NewPoint(Point):
    def __hash__(self):
        return hash(self.x) # maybe self.y as well?
</code></pre>
  
  <p>Ideally your hash should include the same attributes that
  <code>Point.__eq__</code> uses.</p>
  
  <p>Then use NewPoint to construct your objects instead.</p>
</blockquote>

python set intersection ros