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
- Take use lists as inputs.
- Use for loop for checking common members in the list.
- Return true at least one common member in lists.
- 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
Python program to convert multiple numbers from a list into a single number.
Python program to convert words of a list into a single string.
Python program to print elements of the list separately.
Python program to create a sublist of numbers and their squares from 1 to 10.
Python program to create a list of five consecutive numbers in the list.
Python program to insert a given string at the beginning of all items in a list.