find common number in python

Common number in Python

example:num1=[1,2,4,6,8] and num2=[2,5,8,9]
now we have to find from num1 and num2 same 
number is there or not if found the that is our
common number so in both 8 is common number
def common_num(num1,num2):
num=[]
for i in num1:
if i in num2:
num.append(i)
return num
number1=[1,2,3,3]
number2=[1,3,6,3]
print(common_num(number1, number2))

find common number in python

Leave a Comment

Your email address will not be published. Required fields are marked *