Say I have two large lists: list_of_A_objects, which contain objects of class A, and a list of _of_B_objects, which contain objects of class B.
Both of them have line members.
I want to be able to search all the elements in two lists, and if the string member of object A is a substring of the string element of object B, I want it to do something.
What I have is fine if the lists are pretty small, but if the lists are big, it can take a lot of time.
Is there any way to do this faster. I was thinking about using dictionaries in some way because they have a quick search, but I can't figure it out.
This is what I still have.
class A:
def __init__(self, x):
self.string = x
class B:
def __init__(self,x):
self.string = x
list_of_A_objects = get_large_list_of_A_objects()
list_of_B_objects = get_large_list_of_B_objects()
for A_object in list_of_A_objects:
for B_Object in list_of_B_objects:
if A_object.string in B_Object.string:
do_something()