How do you do when there is no common item, posting notices?
Listing 1, 2, and 3 have different index numbers.
def compabilitySorter (lista1, lista2, lista3):
listCompatible=[lista1, lista2, lista3]
checkedItem=set()
commonItem=set()
for i in listCompatible:
for j in i:
if j in checkedItem:
commonItem.add(j)
else:
checkedItem.add(j)
return list(commonItem)
Example 1 (Expected Output):
print(compabilitySorter([1, 2, 4],[2],[2, 3, 6]))
>[2]
When there is no common item, it launches a list with numbers that do not have the required response.
Example 2 (Unintended Output):
print(compabilitySorter([1, 2, 4],[3, 5],[2, 3, 6]))
>[2, 3]