Write a Program that get two lists as input and check if they have at least one common member


This program compares the elements of two lists (list1 and list2) to check if they have any common members. It uses two nested for loops to iterate through the elements of both lists. In the inner loop, for each element x in list1, it compares it with each element y in list2. If any match is found, it sets the variable result to True and prints the value of result.

After both loops have finished executing, the program checks the final value of result. If result is True, it means that the two lists have at least one common member, and the program prints "Lists have at least one common member". If result is still False, it means that the two lists do not have any common members, and the program prints "Lists do not have any common member".

Source Code

list1=[1,2,3,4,5]
list2=[5,6,7,8,9]
result = False
for x in list1:
 for y in list2:
	 if x == y:
		 result = True
		 print(result)
if result:
    print("Lists have at least one common member")
else:
    print("Lists do not have any common member")

Output

True
Lists have at least one common member

Example Programs