I am new to Python and a bit confused about what you can and cannot do with lists. I have two lists that I want to compare and return matching and asymmetric elements in binary format. List1has a constant length, and the length List2is different (but always shorter List1).
For instance:
List1 = ['dog', 'cat', 'pig', 'donkey']
List2 = ['dog', 'cat', 'donkey']
Required Conclusion:
List3 = [1, 1, 0, 1]
The code I have so far is:
def match_nonmatch(List1, List2):
List3 = []
for i in range(len(List1)):
for j in range(len(List2)):
if List1[i] == List2[j]:
List3.append(1)
else:
List3.append(0)
return List3
I can return matches when I compare lists, but when I include the else statement above, returning fuzzy numbers, I get a list that is much longer than it should be. For example, when I use a list comparing 60 elements, I get a list containing 3600 elements, not 60.
, - , , , , , .