Common elements of two lists
Write a function that receives two lists (array) and the common elements in the two lists in the new list
Write a function that receives two lists (array) and the common elements in the two lists in the new list
let msg = 'error' alert(msg)This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error' alert(msg)This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error' alert(msg)This answer is only visible to premium members
This answer is only visible to premium members
def m(): a=[] b=[] c=[] while True : a.append(input("name:")) if "0" in a: break while True : b.append(input("name:")) if "0" in b: break for i in a : if i in b and i!="0" : c.append(i) return c print(m())
def Subscription(list1,list2): final = [] for i in list1: for x in list2: if i == x: final.append(i) return final a = [10,20,30,35,36] b = [30,36,40,50] print(Subscription(a,b))
list1 = ["ali" , 1 , 2 , 3 ,"Reza"] list2 = ["Mamali" ,3 , 5 , "Sara" , "Reza"] list3 = [] for word in list1: if word in list2: list3.append(word) print(list3)
l1 = input("enter element l1: ").split(" ")
l2 = input("enter element l2: ").split(" ")
s1 = set(map(int, l1))
s2 = set(map(int, l2))
print(list(s1 & s2))
let arr1=[10,11,12,15,17] let arr1=[10,21,18,45,17] let finalArr=[] arr1.forEach(function(num){ arr2.forEach(function(num2){ if(num===num2){ finalArr.push(num) } }) }) console.log(finalArr)
lst1=[5,6,9,10,66,57,82] lst2=[66,5,667,84,5,57,33] lst3=[] for i in range(len(lst1)): for j in range(len(lst2)): if lst1[i]==lst2[j]: lst3.append(lst1[i]) print(lst1) print(lst2) print(lst3)
def Moshtarak(n , m) :
s = []def Moshtarak(n , m) :
s = []
for i in n :
if i in m :
s.append(i)
return s
n = eval(input())
m = eval(input())
print(Moshtarak(n , m))
for i in n :
if i in m :
s.append(i)
return s
n = eval(input())
m = eval(input())
print(Moshtarak(n , m))
Submitting answers is currently unavailable.
You must be logged in to access this section.
Login/Sign up If you don’t understand the exercise or can’t solve it for any reason, that’s completely
normal—don’t worry 😊
Try checking out easier exercises and reviewing different answers
submitted by others. Gradually, you can move on to more challenging exercises. Also, your answer
might be correct even if it’s different from others.