写一个函数,判断两个列表是否有交集(不要用for)

# Determine whether two lists have intersection.
def isInter(a,b):	
		result = list(set(a)&set(b))
		if result:
			return True
		else:
			return False
			
    	
# test 
lst1 = [0,1,2,3,4,5,6,7,8,9]
lst2 = [-3,-2,-1,0,1]
a = isInter(lst1,lst2)
print(a)

lst3 = [23,56]
b = isInter(lst1,lst3)
print(b)

测试:

猜你喜欢

转载自blog.csdn.net/GBA_Eagle/article/details/82225613