在我的
Python代码中,我有这个类:
class _Point2D:
def __init__(self, x, y):
self.x = x
self.y = y
def __repr__(self):
return 'point: (' + str(self.x) + ', ' + str(self.y) + ')'
并且有两个列表,initialPointsList和burnedPointsList:
initialPointsList = []
initialPointsList.append(_Point2D(1, 1))
initialPointsList.append(_Point2D(1, 2))
initialPointsList.append(_Point2D(1, 3))
initialPointsList.append(_Point2D(1, 4))
initialPointsList.append(_Point2D(1, 5))
initialPointsList.append(_Point2D(1, 6))
initialPointsList.append(_Point2D(1, 7))
burnedPointsList = []
burnedPointsList.append(_Point2D(1, 2))
burnedPointsList.append(_Point2D(1, 3))
我想计算initialPointsList和burnedPointsList之间的区别
我执行了:
result = set(initialPointsList) - set(burnedPointsList)
for item in result:
print item
并获得以下输出:
point: (1, 1)
point: (1, 4)
point: (1, 5)
point: (1, 6)
point: (1, 2)
point: (1, 3)
point: (1, 7)
但我期待另一个结果,没有烧伤点坐标:
point: (1, 1)
point: (1, 4)
point: (1, 5)
point: (1, 6)
point: (1, 7)
在Python中最好的方法是什么?我的代码有什么不对?