beginner python user, I have to write a function that takes as parameters two lists L1 and L2 and returns a list L3 of elements that are common to L1 and L2. For example: L1=[5,4,6,3,4], L2=[9,4,3,11], then the function returns [4,3] (an element is listed once). Now, I am able to append the elements (find my code below) which is the easy part, but I can't seem to not include the already appended elements.
def common(L1,L2):
L3=[]
for i in range (len(L1)):
for j in range (len(L2)):
if L1[i]==L2[j]:
L3.append(L1[i])
L1=[5,4,6,3,4]
L2=[9,4,3,11]
print(common(L1,L2))
If I try to include a nested loop for L3 and a condition in the if statement, nothing gets printed.