41. Problem to return true if one common member in lists else False.

In this program, we will take two lists as input & return true when there is at least one common member in lists with the help of the below-given steps.

Common member in lists:

Steps to solve the program

  1. Take use lists as inputs.
  2. Use for loop for checking common members in the list.
  3. Return true at least one common member in lists.
  4. Print the output to see the result.
				
					#Input list
list1 = [25,65,77,14,23,96]
list2 = [65,35,62,77]

#Creating result variable
result = False

for val in list1:
    for ele in list2:
        if ele == val:
            result = True
            print(f"{ele} exists in list2", result)
				
			

Output :

				
					65 exists in list2 True
77 exists in list2 True
				
			

Related Articles

Remove all odd index elements.

Convert multiple numbers into a single number

Leave a Comment