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
def same(l1,l2): L3 = [] for i in range(len(l1)): for j in range(len(l2)): if l1[i] == l2[j]: L3.append(l2[j]) return L3 L1 = [] L2 = [] while 1: txt = input("text1: ") if txt == '': break L1.append(txt) while 1: txt = input("text2: ") if txt == '': break L2.append(txt) print(same(L1,L2))
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)
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))
let listArr1=[1,2,3,4,5]; let listArr2 = [2,4,6,8,10]; function CommonElement(listArr1,listArr2) { let newListArr =[]; listArr1.forEach(x => { let elemantOne =x; listArr2.forEach(y =>{ let elemantTwo =y; if(elemantOne == elemantTwo){ newListArr.push(elemantOne); } }); }); console.log(newListArr); } CommonElement(listArr1,listArr2);
package Tax.App; import java.util.ArrayList; public class Anasor_Moshtarak { public static void main(String[] args) { int[] list1 = {7, 6, 17, 11, 19}; int[] list2 = {7, 8, 9, 10, 11,}; ArrayList<Integer> list = new ArrayList<>(); for (int i = 0; i < list1.length; i++) { for (int j = 0; j < list2.length; j++) { if (list1[i] == list2[j]) { list.add(list1[i]); } } } System.out.print(list); } }
def Eshterak(a, b): return a & b S1 = set(input("عناصر اول رو وارد کن: ")) S2 = set(input("عناصر دوم رو وارد کن: ")) result = Eshterak(S1, S2) print(result)
Submitting answers is currently unavailable.
برای استفاده از این بخش باید وارد حساب کاربریت بشی
ورود/ثبت نام 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.