I am curious as to what implementation would be faster in determining if there is a non-similar element in two lists. Here, both lists will be the same in length, and will only have one element that is not in common.
Implementation #1 :
lista = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
listb = ['a', 'b', 'c', 'd', 'e', 'f', 'gslfkjsjf']
difference = list(set(lista) - set(listb))
>>> ['g']
Implementation #2 :
lista = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
listb = ['a', 'b', 'c', 'd', 'e', 'f', 'gslfkjsjf']
for i in range(len(lista)):
if (lista[i] != listb[i]):
print(lista[i])
>>> g
I am interested in knowing the answer as I am trying to find the fastest way to compare two lists of the same length (around 2000 or so, where each element is a unique string. I only used characters for the sake of the example). Thank you to all of those who reply in advance.