我试图找到一个交集组两个位置列表,在ROS不能使用Python交叉口ROS点列表设置
,所以我用Python语言编写代码,我有两个列表,如:
position1 = Point()
position1.x =1
position2 = Point()
position2.x=2
a = [copy.deepcopy(position1),copy.deepcopy(position2)]
b = [copy.deepcopy(position1)]
然后,当我试图让这两个列表A和b
的交集还给我一个答案:集([])
这是荒谬的,
通常我应该有这样一个答案:集(一).intersection(组(B))=集合([位置1])
如果有人可以帮我解决这个问题?
这是伟大的感谢观看这个问题
,我很欣赏你的观看和应答。
在此先感谢。
这里是我的测试代码
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.")
BTW,ROS点类型张贴在这里:http://docs.ros.org/jade/api/geometry_msgs/html/msg/Point.html
它没有看到它如何返回'set([])',显示所有的代码。 – polku
感谢您的回答,我写了一个测试代码,并在我的问题结尾附上 – HOWE
'set's依靠'hash'和'=='来工作...是'hash(position1)'与'散列(position2)'并且'position1 == position2'评估为'True'? –