I have written the following code to find elements in a list that are also within another list. However This algorithm is n squared in Big O, is there a better way of getting around this? thanks in advance
def printCommon(list1,list2):
for i in list1:
found = False
for j in list2:
if i == j:
print i
break
if __name__ == "__main__":
list1 = [1,2,3,4,5]
list2 = [9,8,7,6,5]
printCommon(list1,list2)