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>Well, it doesn't returns <code>set([])</code> but prints <code>set()</code> (nitpicking maybe but it's not the same thing).</p>

<p>Actually it's the expected behavior :</p>

<ul>
<li>a set keeps only unique elements</li>
<li>unique is defined by having the same hash </li>
<li>the default hash comes from <strong>hash</strong>() method</li>
<li><strong>hash</strong>() uses the id of the object</li>
<li>you deepcopy your objects so they have different ids</li>
<li>so they're different</li>
</ul>

<p>I don't know why you think you need deepcopy but if you put your points directly in lists, it will works as expected</p>

python set intersection ros