I have a list of class objects who have two values, x and y. This is my current code to grab an individual object from the list:
for object in object_list:
if object.x == 10 and object.y == 10:
current_object = object
break
And then I can do operations on the object by referencing current_object. However, my problem is that the list contains 2000 class object entries, and I worry that it will be very inefficient to iterate through the list like that until I find the desired object.
Is there a more efficient way for me to get my requested object?
xandyof each corresponding object. Since dictionaries have a better time complexity for searching than lists...dict; specifically, mapping{(foo.x, foo.y): foo, ...}. Also, don't name your own objectsobject...