I need to find the common element from 2 lists, and if there is none, print []. I managed to do the first part, but when I add else it goes sideways...
def find_common(L1,L2):
for element in L1:
if element in L2:
return (element)
else :
return []
L1 = ['Dancing', 'Computers', 'Rowing']
L2 = ['Computers', 'Books', 'Movies']
print(find_common(L1,L2)) #should print "Computers"
L1 = ['Fishing']
L2 = ['Swimming']
print(find_common(L1,L2)) #should print []
The output is for this code is [][] right now. If I don't add the else function, the output is "Computer", which is correct. The problem is that I need to check also some lists that don't have a common element and output [], and here it goes wrong. What is my mistake? Thank you.