1
How to do for when there is no common item, launch warnings?
List 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 (Intended output):
print(compabilitySorter([1, 2, 4],[2],[2, 3, 6]))
>[2]
When there is no common item, launches a list with numbers that have nothing to do with the intended answer.
Example 2 (Output not intended):
print(compabilitySorter([1, 2, 4],[3, 5],[2, 3, 6]))
>[2, 3]