I have a class, and in a list I hold some instances of the class. Before appending a new instance I want to check if x, y are the same with some other item. If x,y exist already in another instance, I want to make another random pair. When I find a pair that is unique I will append the new instance to the list.
What is the most efficient way to check this by using only a list, and checking inside the for loop??
class Vehicle :
def __init__(self, CoordX, CoordY, Z) :
self.X=CoordX
self.Y=CoordY
self.Z=Z
VehicleList=[]
for i in range (1,15+1):
obj_x = randint(1,30)
obj_y = randint (1,20)
obj_z=randint(1,100)
If..#Check if [x,y] of item exists in list and Generate new random
else:
NewVehicle=Vehicle(obj_x,obj_y,obj_z)
VehicleList.append(NewVehicle)