array1 = ['a', 'b', 'c', 'd']
array2 = ['c', 'd', 'e', 'f']
list1 = []
list2 = []
for elem in array1:
if elem in array2:
if elem not in list1:
list1.append(elem)
else:
if elem not in list2:
list2.append(elem)
for elem in array2:
if elem not in array1 and elem not in list2:
list2.append(elem)
print("Values in both arrays:", list1)
print("Values not in both arrays:", list2)
输出结果为:
Values in both arrays: ['c', 'd']
Values not in both arrays: ['a', 'b', 'e', 'f']