I have to implement the following statement:
Design a function that receives two lists and returns common elements to both, without repeating any (intersection of sets). Example: if you receive the lists [1, 2, 1] and [2, 3, 2, 4], you will return the list [2].
I tried the following:
def listas(a,b):
lista_final=[]
for i in a:
for x in b:
if i == b:
lista_final.append(i)
print (lista_final)
lista=[]
lista2=[]
i=0
while i == 0:
num=int(input("Escribe una lista de numeros "))
lista.append(num)
a=str(input("Pulsa x si quieres acabar: "))
if a == 'x':
i=i+1
i=0
while i == 0:
num2=int(input("Escribe una lista de numeros "))
lista2.append(num2)
a=str(input("Pulsa x si quieres acabar: "))
if a == 'x':
i=i+1
listas(lista,lista2)
But I always get an empty list and I do not know how to continue.